Skip to content

Commit 72abe1d

Browse files
FMartinez4okonet
authored andcommittedMar 7, 2018
fix: Wrap open in setTimeout only for IE/Edge. (#578)
Related to #450
1 parent 3c84078 commit 72abe1d

File tree

3 files changed

+49
-3
lines changed

3 files changed

+49
-3
lines changed
 

‎src/index.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import {
88
allFilesAccepted,
99
fileMatchSize,
1010
onDocumentDragOver,
11-
getDataTransferItems
11+
getDataTransferItems,
12+
isIeOrEdge
1213
} from './utils'
1314
import styles from './utils/styles'
1415

@@ -222,7 +223,11 @@ class Dropzone extends React.Component {
222223
// in IE11/Edge the file-browser dialog is blocking, ensure this is behind setTimeout
223224
// this is so react can handle state changes in the onClick prop above above
224225
// see: https://github.com/react-dropzone/react-dropzone/issues/450
225-
setTimeout(this.open.bind(this), 0)
226+
if (isIeOrEdge()) {
227+
setTimeout(this.open.bind(this), 0)
228+
} else {
229+
this.open()
230+
}
226231
}
227232
}
228233

‎src/utils/index.js

+12
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,15 @@ export function allFilesAccepted(files, accept) {
4141
export function onDocumentDragOver(evt) {
4242
evt.preventDefault()
4343
}
44+
45+
function isIe(userAgent) {
46+
return userAgent.indexOf('MSIE') !== -1 || userAgent.indexOf('Trident/') !== -1
47+
}
48+
49+
function isEdge(userAgent) {
50+
return userAgent.indexOf('Edge/') !== -1
51+
}
52+
53+
export function isIeOrEdge(userAgent = window.navigator.userAgent) {
54+
return isIe(userAgent) || isEdge(userAgent)
55+
}

‎src/utils/index.spec.js

+30-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getDataTransferItems } from './'
1+
import { getDataTransferItems, isIeOrEdge } from './'
22

33
const files = [
44
{
@@ -87,3 +87,32 @@ describe('getDataTransferItems', () => {
8787
expect(Object.keys(files[2])).toHaveLength(3)
8888
})
8989
})
90+
91+
describe('isIeOrEdge', () => {
92+
it('should return true for IE10', () => {
93+
const userAgent =
94+
'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0; .NET4.0E; .NET4.0C; .NET CLR 3.5.30729; .NET CLR 2.0.50727; .NET CLR 3.0.30729)'
95+
96+
expect(isIeOrEdge(userAgent)).toBe(true)
97+
})
98+
99+
it('should return true for IE11', () => {
100+
const userAgent =
101+
'Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729; rv:11.0) like Gecko'
102+
expect(isIeOrEdge(userAgent)).toBe(true)
103+
})
104+
105+
it('should return true for Edge', () => {
106+
const userAgent =
107+
'Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 Edge/16.16258'
108+
109+
expect(isIeOrEdge(userAgent)).toBe(true)
110+
})
111+
112+
it('should return false for Chrome', () => {
113+
const userAgent =
114+
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36'
115+
116+
expect(isIeOrEdge(userAgent)).toBe(false)
117+
})
118+
})

0 commit comments

Comments
 (0)
Please sign in to comment.