`type` regression if textarea has no value before typing
See original GitHub issue@testing-library/user-event
version:- Testing Framework and version: 11.4.2
- DOM Environment: jest@26.0.1 @testing-library/jest-dom@5.9.0 @testing-library/react@10.2.1
Relevant code or config
test(" empty textarea", async () => {
render(<textarea data-testid="textbox" />);
await userEvent.type(screen.getByTestId("textbox"), "1234");
expect(screen.getByRole("textbox")).toHaveValue("1234");
});
What you did:
Updated from 11.2.1 to 11.4.2
What happened:
library code types incorrectly if the textarea has no value when it start typing
Reproduction repository: https://codesandbox.io/s/user-event-type-to-add-text-issue-exgpf?file=/src/__tests__/App.test.js
Problem description:
It seems like the “type” event returns to the beginning of the line after it has typed the first letter, after that it returns to normal resulting in the first letter always being at the end of the word/sentence
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:14 (7 by maintainers)
Top Results From Across the Web
How do I preserve line breaks when getting text from a textarea?
The easiest solution is to simply style the element you're inserting the text into with the following CSS property: white-space: pre-wrap;.
Read more >The Textarea element - HTML: HyperText Markup Language
This attribute specifies that the user must fill in a value before submitting a form. rows. The number of visible text lines for...
Read more >HTML textarea tag - W3Schools
The <textarea> tag defines a multi-line text input control. The <textarea> element is often used in a form, to collect user inputs like...
Read more >the text disappears when your typing on input or textarea with ...
Issue 152715: the text disappears when your typing on input or textarea with "text-transform: uppercase" style and you changes the value ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The problem here is that before typing
selectionStart
andselectionEnd
are undefined. I think that can be a problem ofjsdom
instead.@dave-cabbage The reproduction example of this issue works as expected with up-to-date dependencies: https://codesandbox.io/s/user-event-type-to-add-text-issue-forked-dezvq?file=/src/__tests__/App.test.js
Are you by chance using an old version of
jsdom
?If your problem does not resolve by updating the dependencies on your project, please file a new issue with a reproduction example like above. 😃