Skip to content

Commit a8abc49

Browse files
committed
fix: preserve wheel delta remainder
1 parent b4f700c commit a8abc49

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

src/InputNumber.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ const InputNumber = React.forwardRef<InputNumberRef, InputNumberProps>((props, r
607607
// moving mouse wheel rises wheel event with deltaY < 0
608608
// scroll value grows from top to bottom, as screen Y coordinate
609609
onInternalStep(wheelDeltaRef.current < 0, 'wheel');
610-
wheelDeltaRef.current = 0;
610+
wheelDeltaRef.current -= Math.sign(wheelDeltaRef.current) * WHEEL_STEP_DISTANCE;
611611
}
612612
});
613613

tests/wheel.test.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,24 @@ describe('InputNumber.Wheel', () => {
104104
expect(onChange).toHaveBeenCalledWith(1);
105105
});
106106

107+
it('preserves remaining wheel delta after stepping', () => {
108+
const onChange = jest.fn();
109+
const { container } = render(<InputNumber onChange={onChange} changeOnWheel />);
110+
const input = container.querySelector('input');
111+
112+
fireEvent.focus(container.firstChild);
113+
fireEvent.wheel(input, { deltaY: -130 });
114+
expect(onChange).toHaveBeenCalledTimes(1);
115+
expect(onChange).toHaveBeenLastCalledWith(1);
116+
117+
fireEvent.wheel(input, { deltaY: -69 });
118+
expect(onChange).toHaveBeenCalledTimes(1);
119+
120+
fireEvent.wheel(input, { deltaY: -1 });
121+
expect(onChange).toHaveBeenCalledTimes(2);
122+
expect(onChange).toHaveBeenLastCalledWith(2);
123+
});
124+
107125
it('supports line mode wheel delta', () => {
108126
const onChange = jest.fn();
109127
const { container } = render(<InputNumber onChange={onChange} changeOnWheel />);

0 commit comments

Comments
 (0)