Completely updated React, fixed #11, (hopefully)

This commit is contained in:
2018-03-04 19:11:49 -05:00
parent 6e0afd6e2a
commit 34e5f5139a
13674 changed files with 333464 additions and 473223 deletions

View File

@@ -236,16 +236,19 @@ 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
if (this.fileInputEl != null) {
// Returns an object as FileList
const { files } = this.fileInputEl
if (!files.length) {
this.isFileDialogActive = false
}
}
if (typeof onFileDialogCancel === 'function') {
onFileDialogCancel()
}
}, 300)
@@ -438,8 +441,8 @@ Dropzone.propTypes = {
disableClick: PropTypes.bool,
/**
* Enable/disable the dropzone entirely
*/
* Enable/disable the dropzone entirely
*/
disabled: PropTypes.bool,
/**
@@ -468,12 +471,12 @@ Dropzone.propTypes = {
name: PropTypes.string,
/**
* Maximum file size
* Maximum file size (in bytes)
*/
maxSize: PropTypes.number,
/**
* Minimum file size
* Minimum file size (in bytes)
*/
minSize: PropTypes.number,

View File

@@ -264,7 +264,7 @@ describe('Dropzone', () => {
onClickOuterSpy.reset()
onClickInnerSpy.reset()
component.find('Dropzone').simulate('click')
component.find(Dropzone).simulate('click')
expect(onClickOuterSpy.callCount).toEqual(0)
expect(onClickInnerSpy.callCount).toEqual(1)
})
@@ -277,7 +277,7 @@ describe('Dropzone', () => {
</div>
)
component.find('Dropzone').simulate('click')
component.find(Dropzone).simulate('click')
expect(onClickOuterSpy.callCount).toEqual(1)
})
@@ -285,7 +285,7 @@ describe('Dropzone', () => {
const inputPropsClickSpy = spy()
const component = mount(<Dropzone inputProps={{ onClick: inputPropsClickSpy }} />)
component.find('Dropzone').simulate('click')
component.simulate('click')
setTimeout(() => {
expect(inputPropsClickSpy.callCount).toEqual(1)
done()
@@ -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', () => {