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

Paste event ignores preventDefault #861

Closed
Gudahtt opened this issue Feb 24, 2022 · 2 comments · Fixed by #862
Closed

Paste event ignores preventDefault #861

Gudahtt opened this issue Feb 24, 2022 · 2 comments · Fixed by #862

Comments

@Gudahtt
Copy link
Contributor

Gudahtt commented Feb 24, 2022

  • @testing-library/user-event version: 14.0.0-beta.11
  • Testing Framework and version: jest@26.6.3
  • DOM Environment: jsdom@11.5.1

What you did:

I used the new userEvent.paste API to test a form in my application. This form intercepts paste events to split contents among numerous fields, so it is critical that it prevents the clipboard contents from being inserted into the focused input field.

What happened:

During the test, the clipboard contents were all inserted into the focused input element. Calling event.preventDefault in the onPaste handler had no effect.

Reproduction repository:

I would be happy to create a reproduction repository if that would be useful, but I saw a similar unit test here in this repository that I might be able to copy as a simpler representation of the problem. I will pursue that first instead.

Problem description:

When using the new userEvent.paste API with the focus on an editable element, calling event.preventDefault in the onPaste handler has no effect. There is no way to prevent the clipboard contents from being inserted into the editable context.

Suggested solution:

As is already the case for other APIs in this library such as upload, the default behavior of the paste event should be skipped if preventDefault is called on the event.

It looks like a similar problem with the upload API was recently fixed in this PR: #847
I am hoping this problem is able to be fixed in a similar manner.

Gudahtt added a commit to Gudahtt/user-event that referenced this issue Feb 24, 2022
The paste event will now ignore default behavior if
`event.preventDefault` is called on the paste event.

Closes testing-library#861
@Gudahtt
Copy link
Contributor Author

Gudahtt commented Feb 24, 2022

This unit test demonstrates the problem: https://github.com/testing-library/user-event/pull/862/files#diff-d02dcd473de0e9757eaaea55926d26a5083d26f05e9728c42b2b1afbd5428ee1R68

It failed before the changes in that PR were made, but now passes on that branch.

@github-actions
Copy link

github-actions bot commented Mar 1, 2022

🎉 This issue has been resolved in version 14.0.0-beta.12 🎉

The release is available on:

Your semantic-release bot 📦🚀

@ph-fritsche ph-fritsche added this to the userEvent v14 milestone Mar 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants