KarimMokhtar / react-drag-drop-files

Light and simple Reactjs drag and drop files library to use with very flexible options to change, so you put whatever the design you want for your drop-area. Users can drag and drop or even select the file anywhere in the window.
MIT License
248 stars 91 forks source link

Prevent the file picker from triggering when a child element has a click event #119

Open jrods opened 1 year ago

jrods commented 1 year ago

Currently when there are children with onClick events, clicking on those child elements will cause the FileUploader component to open the file picker. Using event.stopPropagation() or event.stopImmediatePropagation() in the child onClick event does not stop the event from triggering.

Example:

<FileUploader {// props}>
  <div onClick={event => {
    event.stopPropagation();
    event.stopImmediatePropagation();
  }}>
    Click me.
  </div>
</FileUploader>
jeon-ilju commented 1 year ago

i have this issue too..

karolstawowski commented 1 year ago

I have tested this issue in my own application - everything seems to be working fine with

onClick={(e) => e.stopPropagation()}

placed on the child component of FileUploader - the file picker does not show up.

plomatteo commented 1 year ago

i have this issue too

sandy-ding commented 1 year ago

I bind on MouseDown event and it worked!

XpTo2k commented 1 year ago

For the ones that onClick={(e) => e.stopPropagation()} doesn't work, try onClickCapture={(e) => e.stopPropagation()}. For more info check this article: event-propagation-event-bubbling-event-catching-beginners-guide..