-
-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: support mouse wheel * Fix scroll, add to simple demo --------- Co-authored-by: Mikhail Petrov <for.mvpetrov@gmail.com>
- Loading branch information
Showing
4 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import KeyCode from 'rc-util/lib/KeyCode'; | ||
import InputNumber from '../src'; | ||
import { fireEvent, render } from './util/wrapper'; | ||
|
||
describe('InputNumber.Wheel', () => { | ||
it('wheel up', () => { | ||
const onChange = jest.fn(); | ||
const { container } = render(<InputNumber onChange={onChange} />); | ||
fireEvent.wheel(container.querySelector('input'), {deltaY: -1}); | ||
expect(onChange).toHaveBeenCalledWith(1); | ||
}); | ||
|
||
it('wheel up with pressing shift key', () => { | ||
const onChange = jest.fn(); | ||
const { container } = render(<InputNumber onChange={onChange} step={0.01} value={1.2} />); | ||
fireEvent.keyDown(container.querySelector('input'), { | ||
which: KeyCode.SHIFT, | ||
key: 'Shift', | ||
keyCode: KeyCode.SHIFT, | ||
shiftKey: true, | ||
}); | ||
fireEvent.wheel(container.querySelector('input'), {deltaY: -1}); | ||
expect(onChange).toHaveBeenCalledWith(1.3); | ||
}); | ||
|
||
it('wheel down', () => { | ||
const onChange = jest.fn(); | ||
const { container } = render(<InputNumber onChange={onChange} />); | ||
fireEvent.wheel(container.querySelector('input'), {deltaY: 1}); | ||
expect(onChange).toHaveBeenCalledWith(-1); | ||
}); | ||
|
||
it('wheel down with pressing shift key', () => { | ||
const onChange = jest.fn(); | ||
const { container } = render(<InputNumber onChange={onChange} step={0.01} value={1.2} />); | ||
fireEvent.keyDown(container.querySelector('input'), { | ||
which: KeyCode.SHIFT, | ||
key: 'Shift', | ||
keyCode: KeyCode.SHIFT, | ||
shiftKey: true, | ||
}); | ||
fireEvent.wheel(container.querySelector('input'), {deltaY: 1}); | ||
expect(onChange).toHaveBeenCalledWith(1.1); | ||
}); | ||
|
||
it('disabled wheel', () => { | ||
const onChange = jest.fn(); | ||
const { container } = render(<InputNumber wheel={false} onChange={onChange} />); | ||
|
||
fireEvent.wheel(container.querySelector('input'), {deltaY: -1}); | ||
expect(onChange).not.toHaveBeenCalled(); | ||
|
||
fireEvent.wheel(container.querySelector('input'), {deltaY: 1}); | ||
expect(onChange).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('wheel is limited to range', () => { | ||
const onChange = jest.fn(); | ||
const { container } = render(<InputNumber onChange={onChange} min={-3} max={3} />); | ||
fireEvent.keyDown(container.querySelector('input'), { | ||
which: KeyCode.SHIFT, | ||
key: 'Shift', | ||
keyCode: KeyCode.SHIFT, | ||
shiftKey: true, | ||
}); | ||
fireEvent.wheel(container.querySelector('input'), {deltaY: -1}); | ||
expect(onChange).toHaveBeenCalledWith(3); | ||
fireEvent.wheel(container.querySelector('input'), {deltaY: 1}); | ||
expect(onChange).toHaveBeenCalledWith(-3); | ||
}); | ||
}); |