react-dropzone: [BUG] In react 18, dragging accepted file over dropzone sets isDragReject to true
Describe the bug Described in issue name
To Reproduce
https://codesandbox.io/s/react-dropzone-example-forked-nfvn0p
Steps to reproduce the behavior:
useDropzone({..., accept: 'image/*'})
drag the image (eg.) over the dropzone, it set state to isDragReject
Expected behavior Should set isDragAccept to true
Desktop (please complete the following information):
- OS: macOs
- Browser Chrome
- Version 99
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 8
- Comments: 21
Commits related to this issue
- feat: add support for React 18 and close #1121, #1167 BREAKING CHANGE: the {draggedFiles} prop on the returned hook state has been removed and the accept/reject state is only computed on drag enter a... — committed to rolandjitsu/react-dropzone by deleted user 2 years ago
- feat: add support for React 18 and close #1121, #1167 BREAKING CHANGE: the {draggedFiles} prop on the returned hook state has been removed and the accept/reject state is only computed on drag enter a... — committed to react-dropzone/react-dropzone by deleted user 2 years ago
- dev: support react-dropzone 14 to fix https://github.com/react-dropzone/react-dropzone/issues/1167 — committed to fgdroege/mui-file-dropzone by fgdroege 8 months ago
@andylacko @vsrc @alfupe @MuscularSloth @travisdahl @kristinzinser could you upgrade to v14 and let me know if the issue is resolved?
Yeah, can confirm same happening with my project but only on Chrome v100.0.4896.88. Safari and Firefox are working fine. I am using React v18 and react-dropzone v12.0.5. But the bug is happening only during the drag stage, as soon as file is dropped correct file gets accepted and wrong file gets rejected.
My suggestion, if there is an issue with browser not allowing the access to the file data during the drag stage I personally think it would be better to have graceful drop to the optimistic resolution. As in
isDragRejectis only true if we can confirm it.In that case we can always add additional instruction to the page about accepted file types and when file gets rejected notify user why it was rejected. With current behavior users get false alarm and spooked when trying to upload valid file formats.
The way accept is processed has changed, it is a breaking change.
Whereas before you could pass accept as, for instance:
accept: [ 'text/csv', 'application/vnd.ms-excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', ]Now you must do it like:
accept: { 'text/*': ['.csv'], 'application/vnd.ms-excel': ['.xls'], 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': ['.xlsx'] }Check this: https://react-dropzone.js.org/#section-accepting-specific-file-types
In my case it is happening in Chrome (tested versions 85 and 100) and React 18. In another project, React 17 and Chrome 100 is working fine.
EDIT: Iโve make it to work reverting from the new way of mounting the root component to the classic one.
๐๐ป
๐๐ผ
It does appear to be working correctly. One thing that would make for a better user experience is to display the extensions rather than the mime-types in the rejection messageโฆ
for example, in the screenshot below it may be easier to parse if it said
File type must be .xls,.xlsx(whats in the arrays)it appears to have resolved with
14.1.1๐ ๐ฅณ thank you for the quick turnaround!@rolandjitsu I tried with v14 and the problem seems to be resolved. Thanks ๐
UPDATE for the issue i was seeing. my problem was actually not defining the
acceptfileTypes well enough. I was using.xls, .xlsxand while it worked in greying out the proper option when i clicked to open the file browser, it was not getting the correct drag styles. What I found here is that I should actually be usingapplication/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet. And when I do, the styles actually work correctly