Skip to content

Commit

Permalink
[Slider] Update Slider onChange, onChangeCommitted
Browse files Browse the repository at this point in the history
- Set onChangeCommitted callback in Slider to receive the last argument passed to onChange
  • Loading branch information
good-jinu committed Dec 17, 2024
1 parent ddc5f5e commit 8a4ebea
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/mui-material/src/Slider/useSlider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ export function useSlider(parameters: UseSliderParameters): UseSliderReturnValue
const [open, setOpen] = React.useState(-1);
const [dragging, setDragging] = React.useState(false);
const moveCount = React.useRef(0);
// lastChangedValue is updated whenever onChange is triggered.
const lastChangedValue = React.useRef<number | number[] | null>(null);

const [valueDerived, setValueState] = useControlled({
controlled: valueProp,
Expand Down Expand Up @@ -567,7 +569,8 @@ export function useSlider(parameters: UseSliderParameters): UseSliderReturnValue
}

if (handleChange && !areValuesEqual(newValue, valueDerived)) {
handleChange(nativeEvent, newValue, activeIndex);
lastChangedValue.current = newValue;
handleChange(nativeEvent, lastChangedValue.current ?? newValue, activeIndex);
}
});

Expand All @@ -587,7 +590,7 @@ export function useSlider(parameters: UseSliderParameters): UseSliderReturnValue
}

if (onChangeCommitted) {
onChangeCommitted(nativeEvent, newValue);
onChangeCommitted(nativeEvent, lastChangedValue.current ?? newValue);
}

touchId.current = undefined;
Expand Down

0 comments on commit 8a4ebea

Please sign in to comment.