New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Show rejected styles when dragging multiple files and multiple==false #410
Conversation
…ragged in multi mode false.
Codecov Report
@@ Coverage Diff @@
## master #410 +/- ##
==========================================
+ Coverage 97.59% 97.63% +0.04%
==========================================
Files 3 3
Lines 166 169 +3
Branches 41 41
==========================================
+ Hits 162 165 +3
Misses 4 4
Continue to review full report at Codecov.
|
src/index.js
Outdated
@@ -79,11 +79,14 @@ class Dropzone extends React.Component { | |||
this.dragTargets.push(e.target); | |||
} | |||
|
|||
const allFilesAccepted = this.allFilesAccepted(getDataTransferItems(e, this.props.multiple)); | |||
// validate all files regardless if they are in multi file mode. | |||
const files = getDataTransferItems(e, true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Shouldn't it be aligned with https://github.com/okonet/react-dropzone/pull/410/files#diff-1fdf421c05c1140f6d71444ea2b27638R133?
true
is default argument, so you can skip it
src/index.js
Outdated
// validate all files regardless if they are in multi file mode. | ||
const files = getDataTransferItems(e, true); | ||
const allFilesAccepted = this.allFilesAccepted(files); | ||
const isMultipleNotAllowed = this.props.multiple ? false : files.length > 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Let's remove negation from the variable name please
- This can be rewritten as
!this.props.multiple || files.length > 1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed the negation with the new changes.
src/index.js
Outdated
|
||
this.setState({ | ||
isDragActive: allFilesAccepted, | ||
isDragReject: !allFilesAccepted | ||
isDragReject: !allFilesAccepted || isMultipleNotAllowed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can allFilesAccepted
be set accordingly before so this code remains intact?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what this means exactly. I just pushed a change so let me know if I need to update it.
This seems to be a breaking change, right? |
@okonet Yeah it is a breaking change. What are your thoughts on adding the extra files on drag to the rejected files or all the files as rejected if it is multiple? Not sure how everyone feels about this but I don't want to have the user experience of a drop of N number of files and it only picking one and saying it is valid. We can do this as breaking change or we can add another config like allowMultipleDrop and default it to true. Setting it to false would show the error class on drag and show any extra files as rejected files. Or we label it as a breaking change and bump the major version. Thoughts? I can submit a PR with these changes. |
@okonet I would push for just making a breaking change, the code will be cleaner and I think the behavior is better for the end user. Also the breaking change would only affect users using multiple=false and it can be easily documented in a change log. |
I think it makes sense to make a major version bump. The change you're proposing makes it more logical. |
Alright great I'll submit a pr with these changes. |
@okonet I just pushed the changes needed to add extra files to rejected when multiple is set to false. Please let me know what the process is for a major version bump. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! We're almost there.
src/index.js
Outdated
@@ -159,6 +158,11 @@ class Dropzone extends React.Component { | |||
} | |||
}); | |||
|
|||
if (!multiple) { | |||
// if not in multi mode add any extra accepted files to rejected. This will allow end users to easily ignore a multi file drop in "single" mode. | |||
rejectedFiles.push(...acceptedFiles.splice(1)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be rewritten with array destructuring?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change acceptedFiles to a let
so it can be redefined and then do something like
const [accepted, ...rejected] = acceptedFiles;
rejectedFiles.push(...rejected);
acceptedFiles = [accepted];
Or just leave it as it is?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's leave as is. Thanks for clarifying.
src/index.js
Outdated
@@ -159,6 +158,11 @@ class Dropzone extends React.Component { | |||
} | |||
}); | |||
|
|||
if (!multiple) { | |||
// if not in multi mode add any extra accepted files to rejected. This will allow end users to easily ignore a multi file drop in "single" mode. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please split the comment into 2 lines
src/index.spec.js
Outdated
@@ -455,44 +455,58 @@ describe('Dropzone', () => { | |||
expect(dropzone.state().isDragReject).toEqual(false); | |||
}); | |||
|
|||
it('should expose acceptedFiles and rejectedFiles to children', () => { | |||
it('multiple false valid files adds to rejected files on a multple drop', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we still keep should
s in tests?
Don't worry about the version bump. I'll take care of this during the merge! |
Hey @plee-nm I've just added some more examples. Could you please check you branch out, run |
@okonet Just ran through the all the examples, looks like everything is working. |
I'm looking at how it works now and it doesn't seem to be any breaking changes. We'll still call |
@okonet it is kind of a gray area because it is fixing undefined behavior. Making it a major would make sure no one that is relying on the undefined behavior is broken. Patch or Major I would have some kind of release note saying: when multiple=false on a multiple file drag it will now show the reject styles/class and add any extra files to the rejected files. |
Thanks for clarification. I think note is enough since we aren't breaking the API. |
…dragged in multi mode false.
What kind of change does this PR introduce?
Did you add tests for your changes?
If relevant, did you update the documentation?
Summary
ATM setting
multiple
tofalse
and dragging multiple files into dropzone will display "accepted" styles although only the first file will be accepted and the rest will be skipped.Changes:
onDrop
will be called with first file asacceptedFiles
argument and the rest of files asrejected
.accept
prop it will also displayrejected
styles in this case.Closes #409
Does this PR introduce a breaking change?
Not really
Other information
Closes #409