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

refactor: dispatch all UI events per one internal API #838

Merged
merged 4 commits into from
Feb 3, 2022

Conversation

ph-fritsche
Copy link
Member

@ph-fritsche ph-fritsche commented Jan 18, 2022

What:

Dispatch user events per one central internal API.

This allows to consistently apply workarounds on the event handling.

Why:

userEvent.upload does not honor event handlers on the click event.
When trying to write a quick fix for this, I discovered that the problem runs deeper.

The trusted UI events by the user trigger a default behavior, but there is also a default behavior for programmatically dispatched events.
Because the latter is executed instantly if no event handler calls event.preventDefault(), any default behavior we simulate trails the programmatically triggered default behavior. This leads to event handlers for the latter observing the wrong document state.
Also some default behavior (like opening the file dialog) depends on event handling that is automatically triggered (clicking a label dispatches a click on the control), but this event is not observed by our implementation.

How:

Refactor how events are created and dispatched.

Checklist:

  • Tests
  • Ready to be merged

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jan 18, 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 bf734dc:

Sandbox Source
userEvent-PR-template Configuration

@codecov
Copy link

codecov bot commented Jan 18, 2022

Codecov Report

Merging #838 (bf734dc) into beta (a5ca2e4) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##              beta      #838   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           81        85    +4     
  Lines         1705      1736   +31     
  Branches       618       619    +1     
=========================================
+ Hits          1705      1736   +31     
Impacted Files Coverage Δ
src/setup/index.ts 100.00% <ø> (ø)
src/clipboard/copy.ts 100.00% <100.00%> (ø)
src/clipboard/cut.ts 100.00% <100.00%> (ø)
src/clipboard/paste.ts 100.00% <100.00%> (ø)
src/document/index.ts 100.00% <100.00%> (ø)
src/event/createEvent.ts 100.00% <100.00%> (ø)
src/event/eventTypes.ts 100.00% <100.00%> (ø)
src/event/index.ts 100.00% <100.00%> (ø)
src/event/wrapEvent.ts 100.00% <100.00%> (ø)
src/keyboard/index.ts 100.00% <100.00%> (ø)
... and 16 more

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 a5ca2e4...bf734dc. Read the comment docs.

@ph-fritsche ph-fritsche changed the title refactor: dispatch elements per UI abstraction refactor: dispatch all UI events per one internal API Feb 3, 2022
@ph-fritsche ph-fritsche marked this pull request as ready for review February 3, 2022 14:22
@ph-fritsche ph-fritsche merged commit 4720ac2 into beta Feb 3, 2022
@ph-fritsche ph-fritsche deleted the refactor-event branch February 3, 2022 14:57
@ph-fritsche ph-fritsche mentioned this pull request Feb 4, 2022
2 tasks
@github-actions
Copy link

github-actions bot commented Feb 7, 2022

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

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.

1 participant