React-dropzone: onDrop not trigger if component is inside modal

Created on 20 Apr 2019  路  3Comments  路  Source: react-dropzone/react-dropzone

Current behaviour
Place the react-dropzone inside a modal component. Open the modal and select a file not triggering onDrop call back.

Steps : https://codesandbox.io/s/3v1r9mm5pm

Expected behaviour
onDrop should be called.

Most helpful comment

After setting noDragEventsBubbling: true it worked. Seems like the modal framework is doing something with those event and stopping the propagation.

https://github.com/react-dropzone/react-dropzone/blob/master/src/index.js#L597

It would be nice to mention it in the docs if parent called the preventDefault(), then onDrop might not be triggered.

All 3 comments

After setting noDragEventsBubbling: true it worked. Seems like the modal framework is doing something with those event and stopping the propagation.

https://github.com/react-dropzone/react-dropzone/blob/master/src/index.js#L597

It would be nice to mention it in the docs if parent called the preventDefault(), then onDrop might not be triggered.

@soumyart the callback invocation is stopped when the event propagation is stopped. This behaves as expected, as explained here.

The fact that noDragEventsBubbling works it's pure coincidence, as it's purpose was to prevent outer dropzones from picking up on drag events in a scenario where you have nested dropzones.

preventDefault() doesn't impact the drag callbacks though.

I think the modal libraries should be responsible for documenting the fact that event propagation will be stopped as the behavior you experience with the dropzone is a symptom of that, not the cause.

See https://github.com/react-dropzone/react-dropzone/issues/799 as well and follow the issue reported on fabric's side.

@rolandjitsu you are right. Silly me fabric document was not clear.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cbougatsa picture cbougatsa  路  3Comments

artsx picture artsx  路  4Comments

0xdevalias picture 0xdevalias  路  4Comments

christiantigre picture christiantigre  路  4Comments

xswordsx picture xswordsx  路  3Comments