question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

onDrop method not being called after selecting a file.

See original GitHub issue

Do you want to request a feature or report a bug?

  • I found a bug
  • I want to propose a feature

What is the current behavior?

When I click the dropzone, the file dialog opens. I select a file either by double clicking or clicking the upload button on the dialog. The dialog dismisses.

About 80% of the time, nothing happens. The onDrop method is not called. The remaining 20% of the time, it works as normal.

File is a valid filetype/size and I see no errors on my console.

If I drag and drop a file from Finder, it consistently works as expected - I’ve only encountered this when selecting from a dialog.

What is the expected behavior?

handleDrop gets called consistently and I’m able to upload my file.

Please mention other relevant information such as the browser version, Operating System and react-dropzone version.

  • My implementation seemingly mirrors the documentation, and I’m using the latest version.
  • My browser is Safari 15, public release version, and I’ve reproduced this using both Big Sur and the Monterrey beta.
  • I have not encountered this issue with other versions of Safari.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:8
  • Comments:20

github_iconTop GitHub Comments

4reactions
jaffemdcommented, Feb 17, 2022

Hi! I just ran into the same issue and I think I finally isolated what’s causing it. It is only happening on Safari for me, Chrome and Firefox function as expected. Versions: react-dropzone: 12.0.2 Safari: Version 15.3 (16612.4.9.1.7, 16612) macOS Big Sur 11.6

The issue seems to be when trying to assign a custom input id for the file input. With this code below, I’m only seeing the onDrop get called around 30% of the time:

import React from 'react';
import { useDropzone } from 'react-dropzone';

export function Uploader() {
  const { getRootProps, getInputProps } = useDropzone({
    onDrop: (acceptedFiles) => console.log('acceptedFiles', acceptedFiles),
  });

  return (
    <div
      {...getRootProps()}
    >
      <label htmlFor="input-id">
        Input Label
      </label>
      <input {...getInputProps({ id: 'input-id' })} />
    </div>
  );
}

With this code below, it gets called 100% of the time:

import React from 'react';
import { useDropzone } from 'react-dropzone';

export function Uploader() {
  const { getRootProps, getInputProps } = useDropzone({
    onDrop: (acceptedFiles) => console.log('acceptedFiles', acceptedFiles),
  });

  return (
    <div
      {...getRootProps()}
    >
      <label htmlFor="input-id">
        Input Label
      </label>
      <input {...getInputProps()} />
    </div>
  );
}

Is there a better way to be able to assign a custom id to the file input? I haven’t seen anything related to this in the docs. Thanks!

Update: Removing the custom id entirely and nesting the input in the label also seems to have the same issue somehow:

<label>
  Input Label
  <input {...getInputProps()} />
</label>
3reactions
meetdheerajcommented, Feb 2, 2022

For me, this isn’t working even for the first time. I’m using React 17+

import Dropzone, { useDropzone } from 'react-dropzone';
...
<Dropzone
              onDrop={(acceptedFiles, fileRejections, event) =>
                console.log('***************', acceptedFiles, fileRejections, event)
              }
              onDropRejected={lol => console.log('##########3', lol)}
            >
              {({ getRootProps, getInputProps }) => (
                <section className="container">
                  <div {...getRootProps()}>
                    <input {...getInputProps()} />

                    <div className={styles.assemblyUploadFormRow}>
                      <div className={styles.dropzoneArea}>
                        <IconButton
                          ariaLabel="file upload"
                          iconProps={{
                            iconName: FluentIconName.CloudUpload,
                          }}
                        />
                        Drag n drop some files here, or click to select files
                      </div>
                    </div>
                  </div>
                </section>
              )}
            </Dropzone>

Those consoles never get printed. On click, I do get file uploader but on selection, nothing happens in the console. Same for drag and drop.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is ondrop not working? - Stack Overflow
I am trying to get drag and drop working, but I am wiring a function to the 'ondrop' event, but the function is...
Read more >
getRootProps - react-dropzone
Prop name Type Default autoFocus bool false children func disabled bool false
Read more >
react-dropzone - npm
Files returned by the hook or passed as arg to the onDrop cb won't have the properties path or fullPath . For more...
Read more >
Drag and Drop File Uploading - CSS-Tricks
I work on an RSS reader app called Readerrr (editor's note: link removed as ... $input.on('change', function(e) { // when drag & drop...
Read more >
HTMLElement: drop event - Web APIs | MDN
The drop event is fired when an element or text selection is dropped on a valid drop target. Syntax. Use the event name...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found