menu icon indicating copy to clipboard operation
menu copied to clipboard

fix: input in menu can not move cursor by arrow keys

Open daskyrk opened this issue 3 years ago • 4 comments

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);
  });

daskyrk avatar Jan 29 '22 09:01 daskyrk

Codecov Report

Merging #434 (6f99700) into master (7b56f09) will increase coverage by 0.00%. The diff coverage is 100.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 Impacted file tree graph

@@           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 data Powered by Codecov. Last update 7b56f09...c2b8d0a. Read the comment docs.

codecov[bot] avatar Jan 29 '22 10:01 codecov[bot]

图片

afc163 avatar Jan 29 '22 11:01 afc163

Could you add test case?

afc163 avatar Jan 31 '22 02:01 afc163

Could you add test case?

Don't know how to simulate keyDown event, the code above not work, do you have any suggestions?

daskyrk avatar Jan 31 '22 07:01 daskyrk