fix: input in menu can not move cursor by arrow keys
Issue demo: https://codesandbox.io/s/ji-ben-antd-4-18-5-forked-orrdd?file=/index.js
Have tried to add test case, but not success to simulate keyDown event(official issue):
it('input and textarea cursor can be moved by arrow', () => {
const wrapper = mount(
<input value='123' onFocus={e => e.target} />,
);
const input = wrapper.find('input');
input.simulate('focus');
const inputNode = input.getDOMNode();
expect(inputNode.selectionStart).toEqual(0);
input.simulate('keyDown', { which: KeyCode.A, keyCode: KeyCode.A });
expect(inputNode.value).toEqual('123A');
expect(inputNode.selectionStart).toEqual(1);
input.simulate('keyDown', { which: KeyCode.LEFT });
expect(inputNode.selectionStart).toEqual(0);
const textarea = wrapper.find('textarea');
textarea.simulate('click');
expect(textarea.selectionStart).toEqual(0);
wrapper.find('Overflow').simulate('keyDown', { which: KeyCode.RIGHT });
expect(textarea.selectionStart).toEqual(1);
wrapper.find('Overflow').simulate('keyDown', { which: KeyCode.LEFT });
expect(textarea.selectionStart).toEqual(0);
});
Codecov Report
Merging #434 (6f99700) into master (7b56f09) will increase coverage by
0.00%. The diff coverage is100.00%.
:exclamation: Current head 6f99700 differs from pull request most recent head c2b8d0a. Consider uploading reports for the commit c2b8d0a to get more accurate results
@@ Coverage Diff @@
## master #434 +/- ##
=======================================
Coverage 99.84% 99.84%
=======================================
Files 25 25
Lines 651 654 +3
Branches 169 171 +2
=======================================
+ Hits 650 653 +3
Misses 1 1
| Impacted Files | Coverage Δ | |
|---|---|---|
| src/hooks/useAccessibility.ts | 100.00% <100.00%> (ø) |
|
| src/Menu.tsx | 100.00% <0.00%> (ø) |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing dataPowered by Codecov. Last update 7b56f09...c2b8d0a. Read the comment docs.
Could you add test case?
Could you add test case?
Don't know how to simulate keyDown event, the code above not work, do you have any suggestions?