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

Typing {arrowleft} doesn't change the selection #690

Closed
Ayc0 opened this issue Jun 24, 2021 · 4 comments · Fixed by #686
Closed

Typing {arrowleft} doesn't change the selection #690

Ayc0 opened this issue Jun 24, 2021 · 4 comments · Fixed by #686
Labels
enhancement New feature or request

Comments

@Ayc0
Copy link

Ayc0 commented Jun 24, 2021

  • @testing-library/user-event version: 13.x.x -> 13.1.9
  • Testing Framework and version: jest 27 (same behavior in jest 26)
  • DOM Environment: jsdom provided by jest
expect(textArea.selectionStart).toBe(5);
fireEvent.type(textArea, "{arrowleft}");
expect(textArea.selectionStart).toBe(4); // ❌  doesn't pass

What happened:

image

Reproduction repository:

There is a full reproduction here: https://codesandbox.io/s/testing-libraryuser-event-bug-with-arrows-62f7g

Problem description: the selection should be shifted by 1 to the left (to 4) instead of staying at its initial position (at 5)

Suggested solution: No idea

@Ayc0
Copy link
Author

Ayc0 commented Jun 24, 2021

I also have a similar bug with initialSelectionStart, I think it's related to the same issue, but I'm not sure (maybe I should open another issue for that):

image

@ph-fritsche
Copy link
Member

There are two things:

  1. element.focus() does nothing if the element is not inserted in the DOM. Insert your element somewhere in the body.
  2. Textarea is not supported yet. It looks like this will change with feat: keydownBehavior for textarea #686 😄

@ph-fritsche ph-fritsche linked a pull request Jul 9, 2021 that will close this issue
3 tasks
@ph-fritsche ph-fritsche added the enhancement New feature or request label Jul 9, 2021
@Ayc0
Copy link
Author

Ayc0 commented Jul 9, 2021

element.focus() does nothing if the element is not inserted in the DOM. Insert your element somewhere in the body.

I had the same issue even when adding the elements to the body, but I updated the sandbox to fix that in the example:

image

@Ayc0
Copy link
Author

Ayc0 commented Jul 9, 2021

Textarea is not supported yet

I didn't know!
Thanks for having linked the PR addressing the issue 🙇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants