Skip to content

Commit

Permalink
fix: restore isFileDialogActive to false after the FileDialog was clo…
Browse files Browse the repository at this point in the history
…sed (#556)
  • Loading branch information
finico authored and okonet committed Jan 19, 2018
1 parent 8e4ae3f commit 0eb69bb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/index.js
Expand Up @@ -236,16 +236,17 @@ class Dropzone extends React.Component {
onFileDialogCancel() {
// timeout will not recognize context of this method
const { onFileDialogCancel } = this.props
const { fileInputEl } = this
let { isFileDialogActive } = this
// execute the timeout only if the onFileDialogCancel is defined and FileDialog
// is opened in the browser
if (onFileDialogCancel && isFileDialogActive) {
// execute the timeout only if the FileDialog is opened in the browser
if (this.isFileDialogActive) {
setTimeout(() => {
// Returns an object as FileList
const FileList = fileInputEl.files
if (!FileList.length) {
isFileDialogActive = false
const { files } = this.fileInputEl

if (!files.length) {
this.isFileDialogActive = false
}

if (typeof onFileDialogCancel === 'function') {
onFileDialogCancel()
}
}, 300)
Expand Down
20 changes: 20 additions & 0 deletions src/index.spec.js
Expand Up @@ -981,6 +981,26 @@ describe('Dropzone', () => {
}, 300)
}, 0)
})

it('should restore isFileDialogActive to false after the FileDialog was closed', done => {
const component = mount(<Dropzone />)

spy(component.instance(), 'open')
component.simulate('click')

setTimeout(() => {
expect(component.instance().isFileDialogActive).toEqual(true)

const evt = document.createEvent('HTMLEvents')
evt.initEvent('focus', false, true)
document.body.dispatchEvent(evt)

setTimeout(() => {
expect(component.instance().isFileDialogActive).toEqual(false)
done()
}, 300)
}, 0)
})
})

describe('nested Dropzone component behavior', () => {
Expand Down

0 comments on commit 0eb69bb

Please sign in to comment.