Textarea `type` does not respect selection range
See original GitHub issue@testing-library/user-event
version: 12.1.4- Testing Framework and version: jest
- DOM Environment: jsdom
Relevant code or config: Check out this pull request. I added a test to demonstrate the use case I ran into and to show the bug. I don’t intent to merge the PR, it’s simple there to as a simple reproducible version of my issue.
What you did:
- Textarea has some text
"foo"
- Call
textarea.setSelectionRange(0,0)
to put cursor at the beginning of the textarea. - Call
type
to add some text"bar"
- Expected textarea value should have
"barfoo"
What happened:
- textarea value is
"foobar"
Image of running the test locally:
Reproduction repository: Check out this pull request.
Somewhat hilariously, I’m actually using the library to simulate user behavior on Roam. I know the library is not designed for that and meant for testing, is there any concern with using it in this way? I was able to reproduce the issue I was running into in a testing use case anyway, as evidenced by the linked pull request above.
Here’s my relevant use case anyway: https://github.com/dvargas92495/roam-js-extensions/blob/master/src/entries/todont.ts#L51-L53
Problem description:
I would expect moving the cursor using setSelectionRange
would result in subsequent type
calls to respect that invocation.
Suggested solution:
I haven’t dove into the user-event
source code yet, but if we agree that this is a bug, I would love to take a shot a solving this!
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
ah I needed to do both:
going to close the linked PR! Thanks for your help!
I was supsecting this but I didn’t try yet. I was thinking if this is really correct.
The the parameters are used only when the initial selection is 0. I guess they should be used everytime they are provided