Skip to content

Commit

Permalink
ensure onBeforeChange is called when clicking the rail (#822)
Browse files Browse the repository at this point in the history
* ensure onBeforeChange is called when clicking the rail

* add test case

* hopefully fix tests, address comments
  • Loading branch information
dasl- authored Apr 12, 2022
1 parent 46936f0 commit 0c209f0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Slider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ const Slider = React.forwardRef((props: SliderProps, ref: React.Ref<SliderRef>)
cloneNextValues.push(newValue);
}

onBeforeChange?.(getTriggerValue(cloneNextValues));
triggerChange(cloneNextValues);
onAfterChange?.(getTriggerValue(cloneNextValues));
}
Expand Down
20 changes: 20 additions & 0 deletions tests/Slider.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,26 @@ describe('Slider', () => {

expect(onChange).toHaveBeenCalledWith([20, 20]);
});

it('should call onBeforeChange, onChange, and onAfterChange', () => {
const onBeforeChange = jest.fn();
const onChange = jest.fn();
const onAfterChange = jest.fn();
const { container } = render(
<Slider
onBeforeChange={onBeforeChange}
onChange={onChange}
onAfterChange={onAfterChange}
/>,
);
fireEvent.mouseDown(container.querySelector('.rc-slider'), {
clientX: 20,
});

expect(onBeforeChange).toHaveBeenCalledWith(20);
expect(onChange).toHaveBeenCalledWith(20);
expect(onAfterChange).toHaveBeenCalledWith(20);
});
});

it('autoFocus', () => {
Expand Down

1 comment on commit 0c209f0

@vercel
Copy link

@vercel vercel bot commented on 0c209f0 Apr 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.