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(paste): skip input according to defaultPrevented #862

Merged
merged 5 commits into from Mar 1, 2022

Conversation

Gudahtt
Copy link
Contributor

@Gudahtt Gudahtt commented Feb 24, 2022

What:
The paste event now uses the central event dispatching system introduced in #847 to implement the effects of the paste event, which ensures the effects are skipped if event.preventDefault is called.

Why:
This ensures that the effect of the paste event is ignored if event.preventDefault() is called on the paste event. This matches the behavior of the paste event in the browser, and is necessary to test sites that rely on this behavior. This fixes #861.

How:
The behavior of the paste event (which is to insert the clipboard content into the current context if it is editable) has been moved from the paste module to a separate module in the behavior directory. This effect of pasting is now called by the event dispatching system, which also ensures this effect is suppressed if event.preventDefault is called.

Checklist:

  • Tests
  • Ready to be merged

The paste event will now ignore default behavior if
`event.preventDefault` is called on the paste event.

Closes testing-library#861
@codesandbox-ci
Copy link

codesandbox-ci bot commented Feb 24, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 1a45005:

Sandbox Source
userEvent-PR-template Configuration

src/event/behavior/paste.ts Outdated Show resolved Hide resolved
src/event/behavior/paste.ts Outdated Show resolved Hide resolved
src/event/behavior/paste.ts Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Feb 24, 2022

Codecov Report

Merging #862 (1a45005) into beta (5ea38e8) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##              beta      #862   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           82        83    +1     
  Lines         1717      1721    +4     
  Branches       614       615    +1     
=========================================
+ Hits          1717      1721    +4     
Impacted Files Coverage Δ
src/clipboard/paste.ts 100.00% <ø> (ø)
src/event/behavior/paste.ts 100.00% <100.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 5ea38e8...1a45005. Read the comment docs.

tests/clipboard/paste.ts Outdated Show resolved Hide resolved
tests/clipboard/paste.ts Outdated Show resolved Hide resolved
tests/clipboard/paste.ts Outdated Show resolved Hide resolved
@ph-fritsche ph-fritsche changed the title fix(paste): Fix prevent default behavior fix(paste): skip input according to defaultPrevented Feb 25, 2022
Gudahtt and others added 3 commits February 25, 2022 13:06
Co-authored-by: Philipp Fritsche <ph.fritsche@gmail.com>
Co-authored-by: Philipp Fritsche <ph.fritsche@gmail.com>
Co-authored-by: Philipp Fritsche <ph.fritsche@gmail.com>
Copy link
Member

@ph-fritsche ph-fritsche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for taking the time to contribute to this project ❤️

@ShaneYu
Copy link

ShaneYu commented Feb 28, 2022

Any idea when this PR is going to be merged and a new package released? As far as I can tell, there is no workaround(s) at the moment for this issue and is therefore needing much complicated tests to achieve something simple.

@ph-fritsche ph-fritsche added this to the userEvent v14 milestone Mar 1, 2022
@ph-fritsche ph-fritsche merged commit d3d71ac into testing-library:beta Mar 1, 2022
@ph-fritsche
Copy link
Member

@all-contributors add @Gudahtt bug, code

@allcontributors
Copy link
Contributor

@ph-fritsche

I've put up a pull request to add @Gudahtt! 🎉

@github-actions
Copy link

github-actions bot commented Mar 1, 2022

🎉 This PR is included in version 14.0.0-beta.12 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Paste event ignores preventDefault
3 participants