File tree 3 files changed +49
-3
lines changed
3 files changed +49
-3
lines changed Original file line number Diff line number Diff line change 8
8
allFilesAccepted ,
9
9
fileMatchSize ,
10
10
onDocumentDragOver ,
11
- getDataTransferItems
11
+ getDataTransferItems ,
12
+ isIeOrEdge
12
13
} from './utils'
13
14
import styles from './utils/styles'
14
15
@@ -222,7 +223,11 @@ class Dropzone extends React.Component {
222
223
// in IE11/Edge the file-browser dialog is blocking, ensure this is behind setTimeout
223
224
// this is so react can handle state changes in the onClick prop above above
224
225
// 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
+ }
226
231
}
227
232
}
228
233
Original file line number Diff line number Diff line change @@ -41,3 +41,15 @@ export function allFilesAccepted(files, accept) {
41
41
export function onDocumentDragOver ( evt ) {
42
42
evt . preventDefault ( )
43
43
}
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
+ }
Original file line number Diff line number Diff line change 1
- import { getDataTransferItems } from './'
1
+ import { getDataTransferItems , isIeOrEdge } from './'
2
2
3
3
const files = [
4
4
{
@@ -87,3 +87,32 @@ describe('getDataTransferItems', () => {
87
87
expect ( Object . keys ( files [ 2 ] ) ) . toHaveLength ( 3 )
88
88
} )
89
89
} )
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
+ } )
You can’t perform that action at this time.
0 commit comments