Skip to content

Commit 0c209f0

Browse files
authored
ensure onBeforeChange is called when clicking the rail (#822)
* ensure onBeforeChange is called when clicking the rail * add test case * hopefully fix tests, address comments
1 parent 46936f0 commit 0c209f0

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/Slider.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ const Slider = React.forwardRef((props: SliderProps, ref: React.Ref<SliderRef>)
298298
cloneNextValues.push(newValue);
299299
}
300300

301+
onBeforeChange?.(getTriggerValue(cloneNextValues));
301302
triggerChange(cloneNextValues);
302303
onAfterChange?.(getTriggerValue(cloneNextValues));
303304
}

tests/Slider.test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,26 @@ describe('Slider', () => {
537537

538538
expect(onChange).toHaveBeenCalledWith([20, 20]);
539539
});
540+
541+
it('should call onBeforeChange, onChange, and onAfterChange', () => {
542+
const onBeforeChange = jest.fn();
543+
const onChange = jest.fn();
544+
const onAfterChange = jest.fn();
545+
const { container } = render(
546+
<Slider
547+
onBeforeChange={onBeforeChange}
548+
onChange={onChange}
549+
onAfterChange={onAfterChange}
550+
/>,
551+
);
552+
fireEvent.mouseDown(container.querySelector('.rc-slider'), {
553+
clientX: 20,
554+
});
555+
556+
expect(onBeforeChange).toHaveBeenCalledWith(20);
557+
expect(onChange).toHaveBeenCalledWith(20);
558+
expect(onAfterChange).toHaveBeenCalledWith(20);
559+
});
540560
});
541561

542562
it('autoFocus', () => {

0 commit comments

Comments
 (0)