Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/Handles/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export interface HandlesProps {
}

export interface HandlesRef {
focus: (index: number) => void;
focus: (index: number, options?: FocusOptions) => void;
hideHelp: VoidFunction;
}

Expand Down Expand Up @@ -66,8 +66,12 @@ const Handles = React.forwardRef<HandlesRef, HandlesProps>((props, ref) => {

// =========================== Render ===========================
React.useImperativeHandle(ref, () => ({
focus: (index: number) => {
handlesRef.current[index]?.focus();
focus: (index: number, options?: FocusOptions) => {
if (options) {
handlesRef.current[index]?.focus(options);
} else {
handlesRef.current[index]?.focus();
}
},
hideHelp: () => {
flushSync(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/Slider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ const Slider = React.forwardRef<SliderRef, SliderProps<number | number[]>>((prop

if (e) {
(document.activeElement as HTMLElement)?.blur?.();
handlesRef.current!.focus(focusIndex);
handlesRef.current!.focus(focusIndex, { preventScroll: true });
onStartDrag(e, focusIndex, cloneNextValues);
} else {
// https://github.com/ant-design/ant-design/issues/49997
Expand Down
11 changes: 11 additions & 0 deletions tests/Slider.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ describe('Slider', () => {
});
});

it('does not scroll the page when focusing a handle from a track press', () => {
const { container } = render(<Slider defaultValue={25} />);
const slider = container.querySelector('.rc-slider');
const handle = container.querySelector('.rc-slider-handle');
const focus = jest.spyOn(handle, 'focus');

fireEvent.mouseDown(slider, { clientX: 50, clientY: 0 });

expect(focus).toHaveBeenCalledWith({ preventScroll: true });
});

it('should render Slider correctly where value > startPoint', () => {
const { container } = render(<Slider value={50} startPoint={20} />);
expect(container.getElementsByClassName('rc-slider-handle')[0]).toHaveStyle({ left: '50%' });
Expand Down
Loading