Skip to content

fix(upload): fix order of events#847

Merged
ph-fritsche merged 3 commits intobetafrom
fix-upload
Feb 7, 2022
Merged

fix(upload): fix order of events#847
ph-fritsche merged 3 commits intobetafrom
fix-upload

Conversation

@ph-fritsche
Copy link
Copy Markdown
Member

@ph-fritsche ph-fritsche commented Feb 4, 2022

What:

Replace default behavior as part of the central event dispatching.

Why:

The order of events for userEvent.upload was incorrect.

When clicking the <input type="file"/> element in the browser:

  1. The element is focused on mousedown
  2. The file dialog is opened, which results in a blur event on the element.
  3. The user selects one or more files, which results in an input and change event.
  4. The file dialog is closed, which results in a focus event on the element.

Event handlers on the click event can prevent opening the file dialog in the browser.
The previous implementation did not honor Event.defaultPrevented.

How:

Implement default behavior as plugins to the central dispatchUIEvent introduced in #838 .

If a default behavior is implemented by this library, the default behavior implemented by the DOM implementation is disabled per event.preventDefault().
Then event.defaultPrevented and event.preventDefault() are replaced so that event handlers can use them as usual.

Checklist:

  • Tests
  • Ready to be merged

@ph-fritsche ph-fritsche added this to the userEvent v14 milestone Feb 4, 2022
@codesandbox-ci
Copy link
Copy Markdown

codesandbox-ci Bot commented Feb 4, 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 ab1361e:

Sandbox Source
userEvent-PR-template Configuration

@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 4, 2022

Codecov Report

Merging #847 (ab1361e) into beta (4720ac2) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##              beta      #847   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           85        89    +4     
  Lines         1736      1762   +26     
  Branches       619       622    +3     
=========================================
+ Hits          1736      1762   +26     
Impacted Files Coverage Δ
src/event/behavior/click.ts 100.00% <100.00%> (ø)
src/event/behavior/registry.ts 100.00% <100.00%> (ø)
src/event/dispatchEvent.ts 100.00% <100.00%> (ø)
src/event/index.ts 100.00% <100.00%> (ø)
src/pointer/pointerPress.ts 100.00% <100.00%> (ø)
src/utility/upload.ts 100.00% <100.00%> (ø)
src/utils/misc/cloneEvent.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 4720ac2...ab1361e. Read the comment docs.

@ph-fritsche ph-fritsche merged commit 214fd03 into beta Feb 7, 2022
@ph-fritsche ph-fritsche deleted the fix-upload branch February 7, 2022 10:46
@github-actions
Copy link
Copy Markdown

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