Skip to content

Commit

Permalink
Refactor slider
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonMHasperhoven committed Nov 27, 2024
1 parent 364e42d commit b1128b6
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions packages/ui/src/Slider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export const Slider: React.FC<SliderProps> = ({
min = 0,
max = 100,
step = 1,
value: valueProp = 0,
defaultValue = 0,
value: valueProp,
defaultValue,
onChange,
leftLabel,
rightLabel,
Expand All @@ -39,15 +39,17 @@ export const Slider: React.FC<SliderProps> = ({
valueDetails,
disabled = false,
}) => {
const [value, setValue] = useState(valueProp || defaultValue);
const [value, setValue] = useState(valueProp ?? defaultValue ?? 0);
const handleValueChange = (newValue: number[]) => {
const updatedValue = newValue[0] ?? defaultValue;
const updatedValue = newValue[0] ?? defaultValue ?? 0;
setValue(updatedValue);
onChange?.(updatedValue);
};

useEffect(() => {
setValue(valueProp);
if (valueProp !== undefined) {
setValue(valueProp);
}
}, [valueProp]);

const totalSteps = (max - min) / step;
Expand Down

0 comments on commit b1128b6

Please sign in to comment.