Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

daskyrk
Copy link

@daskyrk daskyrk commented Jan 29, 2022

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
Copy link

codecov bot commented Jan 29, 2022

Codecov Report

Merging #434 (6f99700) into master (7b56f09) will increase coverage by 0.00%.
The diff coverage is 100.00%.

❗ 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.

@afc163
Copy link
Member

afc163 commented Jan 29, 2022

图片

@afc163
Copy link
Member

afc163 commented Jan 31, 2022

Could you add test case?

@daskyrk
Copy link
Author

daskyrk commented Jan 31, 2022

Could you add test case?

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

@delete-merged-branch delete-merged-branch bot deleted the branch react-component:master March 31, 2023 07:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants