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.

[BUG] File dialog enables only the first file type from accept, others are disabled

See original GitHub issue

Describe the bug When defining the accept object like

useDropzone({
  accept: {
    'image/jpeg': [],
    'image/png': [],
  }
})

the file drop option works properly. In case the user wants to pick a file from file dialog, only the first file type from accept is enabled, the rest are disabled and greyed out.

To Reproduce Steps to reproduce the behavior:

  1. Go to “Accepting specific file types”: Click me
  2. Click on the dropzone field
  3. File dialog opens up
  4. User can select a .jpeg file, but not a .png file

Expected behavior All defined file types in the accept object should be enabled for selection via file dialog

Desktop:

  • OS: macOS Monterey (Version 12.3.1)
  • Browser: Chrome (Version 101.0.4951.54 (Official Build) (x86_64))
  • React DropZone: 14.2.0

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6

github_iconTop GitHub Comments

10reactions
GlennBlicharzBounteouscommented, May 9, 2022

@shomyx - I had the same issue/confusion. It wasn’t obvious to me that only one file type was selected, because MacOS Catalina doesn’t show the “Options” select box by default. I read the discussion / tickets that @rolandjitsu provided on the File System Access API, and opted to disable that feature by adding useFsAccessApi: false to the useDropzone configuration.

const { fileRejections, getRootProps, getInputProps, open, isDragActive } = useDropzone({
    onDrop,
    noClick: true,
    noKeyboard: true,
    useFsAccessApi: false,
    accept: {
        'image/png': ['.png'],
        'image/jpeg': ['.jpg', '.jpeg'],
        'application/pdf': ['.pdf'],
        'application/msword': ['.doc'],
        'application/vnd.openxmlformats-officedocument.wordprocessingml.document': ['.docx']
    },
    maxSize: 2000000,
    multiple: true
});

This, to me, works as expected. The one drawback, is that it combines all of the accepted file types into a single “Custom Files” entry in the “Options” select box. You may want to vote on having the File System Access API disabled by default: https://github.com/react-dropzone/react-dropzone/discussions/1186

1reaction
rolandjitsucommented, May 7, 2022

@shomyx that’s expected behaviour when using the File System Access API. If you check the screencast I’ve attached, you’ll see that you need to select the option to select other mime types based on the accept attr.

https://user-images.githubusercontent.com/1479737/167239126-15ef8900-ecad-4b13-9605-e2a217b72b7a.mp4

Read more comments on GitHub >

github_iconTop Results From Across the Web

1054966 - Policy page opens a file dialogue even if the Allow ...
1. Start the Chromium browser with the "AllowFileSelectionDialogue" policy disabled. 2. Open the internal policy page (chrome://policy). 3. Press the "Export to ...
Read more >
OpenFileDialog Class (System.Windows.Forms)
Gets or sets a value indicating whether the OK button of the dialog box is disabled until the user navigates the view or...
Read more >
How to remove All Files option from file input dialog?
It will allow all image types, and in case of mobile devices ... <input type="file" accept="image/*"> //This will match all image files.
Read more >
How to Use File Choosers - Oracle Help Center
Another way to present a file chooser is to add an instance of JFileChooser to a ... Bringing up a standard open dialog...
Read more >
<input type="file"> - HTML: HyperText Markup Language | MDN
The accept attribute value is a string that defines the file types the file input should accept. This string is a comma-separated list...
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