Skip to content
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

Fix: Dragging multiple files when multiple false doesn't apply rejectStyle #489

Merged
merged 9 commits into from
Sep 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/index.js
Expand Up @@ -342,7 +342,8 @@ class Dropzone extends React.Component {
...appliedStyle,
...acceptStyle
}
} else if (rejectStyle && isDragReject) {
}
if (rejectStyle && isDragReject) {
appliedStyle = {
...appliedStyle,
...rejectStyle
Expand Down
65 changes: 65 additions & 0 deletions src/index.spec.js
Expand Up @@ -9,6 +9,19 @@ const DummyChildComponent = () => null
let files
let images

const rejectColor = 'red'
const acceptColor = 'green'

const rejectStyle = {
color: rejectColor,
borderColor: 'black'
}

const acceptStyle = {
color: acceptColor,
borderWidth: '5px'
}

describe('Dropzone', () => {
beforeEach(() => {
files = [
Expand Down Expand Up @@ -395,6 +408,58 @@ describe('Dropzone', () => {
expect(child).toHaveProp('isDragReject', true)
})

it('should apply acceptStyle if multiple is false and single file', () => {
const dropzone = mount(
<Dropzone
accept="image/*"
multiple={false}
acceptStyle={acceptStyle}
rejectStyle={rejectStyle}
>
{props => <DummyChildComponent {...props} />}
</Dropzone>
)
dropzone.simulate('dragEnter', { dataTransfer: { files: [images[0]] } })
const mainDiv = dropzone.find('div').at(0)
expect(mainDiv).toHaveProp('style', acceptStyle)
})

it('should apply rejectStyle if multiple is false and single bad file type', () => {
const dropzone = mount(
<Dropzone
accept="image/*"
multiple={false}
acceptStyle={acceptStyle}
rejectStyle={rejectStyle}
>
{props => <DummyChildComponent {...props} />}
</Dropzone>
)
dropzone.simulate('dragEnter', { dataTransfer: { files: [files[0]] } })
const mainDiv = dropzone.find('div').at(0)
expect(mainDiv).toHaveProp('style', rejectStyle)
})

it('should apply acceptStyle + rejectStyle if multiple is false and multiple good file types', () => {
const dropzone = mount(
<Dropzone
accept="image/*"
multiple={false}
acceptStyle={acceptStyle}
rejectStyle={rejectStyle}
>
{props => <DummyChildComponent {...props} />}
</Dropzone>
)
dropzone.simulate('dragEnter', { dataTransfer: { files: images } })
const mainDiv = dropzone.find('div').at(0)
const expectedStyle = {
...acceptStyle,
...rejectStyle
}
expect(mainDiv).toHaveProp('style', expectedStyle)
})

it('should set proper dragActive state if accept prop changes mid-drag', () => {
const dropzone = mount(
<Dropzone accept="image/*">
Expand Down