-
Notifications
You must be signed in to change notification settings - Fork 35
Description
As the title says, even when there are errors, the method onChange is called. I've found 2 scenarios that can trigger this:
Scenario 1:
- Set the accepts prop to something like: ['image/jpg', 'image/jpeg', 'image/png']
- Select a PDF from the select files dialog
In my case, I can change the type filter in the dialog box to "All file types (*)". With this option, PDFs are visible and I can select them. After selecting a PDF or another file that it is not in the accepts prop, the onError method is called as the onChange method is called with an empty array.
This can be sorted checking that the array has elements.
Scenario 2:
- Set the accepts prop to something like: ['image/jpg', 'image/jpeg', 'image/png']
- Set the multiple prop to true
- Select more than one file where one of those has an invalid extension
Again, the type filter in the select files dialog box can be changed to "All file types (*)". In this case, the onError method is called with the first file that is invalid, the onChange method is called with the files that were processed before the invalid file was encountered. Files that come after the invalid one are not processed.
Where is the issue
It is in the handleDrop method inside the index.js file. Changes to be made to this file depend on how errors are going to be handled:
- You can stop when the first error is found and do not call onChange.
- You can call onError for every invalid file or send an array of errors, and call onChange if there is any valid file.
In any case, calling onChange with an empty array can be misleading for the users of the library.