<Dropzone> cause onClick to fire twice on parent <div>
See original GitHub issueI ran into an issue with click handlers and drag handlers being fired twice on a <div>
, and found that it happens when I have <Dropzone>
as a child of the <div>
.
Before <Dropzone>
:
<div onClick={e => console.log("click", e)}>
</div>
Clicking the <div>
results in:
After <Dropzone>
:
<div onClick={e => console.log("click", e)}>
<Dropzone className="upload-drop-area"
activeClassName="upload-drop-area-accept"
rejectClassName="upload-drop-area-reject"
multiple={false}
onDragEnter={this.onDragEnter}
onDragLeave={this.onDragLeave}
onDropAccepted={this.onDropAccepted}>
</Dropzone>
</div>
Clicking the <div>
results in two events:
I’ve never seen this kind of thing in React before. Any idea what’s going on?
Issue Analytics
- State:
- Created 7 years ago
- Comments:47
Top Results From Across the Web
Dropzone opens file chooser twice - Stack Overflow
This bug happens when your clickable element is already an input[type=file]. Dropzone injects another one and now you have two.
Read more >react-dropzone
Simple React hook to create a HTML5-compliant drag'n'drop zone for files. Documentation and examples at https://react-dropzone.js.org.
Read more >Event Bubbling and Event Catching in JavaScript and React
She has a single parent div with an onClick event handler that, when clicked, calls everyone to the table to eat her food....
Read more >How to correctly use preventDefault(), stopPropagation(), or ...
A fileUpload function to trigger the click event on the file upload input . Assigning both the dropzone div and a button to...
Read more >Introduction to browser events - The Modern JavaScript Tutorial
click – when the mouse clicks on an element (touchscreen devices ... and use double quotes inside, like this: onclick="alert("Click!
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 Free
Top 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
Just add a
pointer-events: none;
css-rule on the dropzone DIV dom-node… that fixed it for me.Maybe a few more pointers: I experienced the same issue as here but it only seems to happen in Chrome. Firefox handles it correctly (IMO). Code to paste on https://react-dropzone.js.org:
Reproducing:
Using
e.preventDefault()
doesn’t help:only removing the
onClick
handler seems to help and all still works.