@@ -32,6 +32,8 @@ class Dropzone extends React.Component {
3232 this . onDrop = this . onDrop . bind ( this )
3333 this . onFileDialogCancel = this . onFileDialogCancel . bind ( this )
3434 this . setRef = this . setRef . bind ( this )
35+ this . setRefs = this . setRefs . bind ( this )
36+ this . onInputElementClick = this . onInputElementClick . bind ( this )
3537 this . isFileDialogActive = false
3638 this . state = {
3739 draggedFiles : [ ] ,
@@ -48,6 +50,7 @@ class Dropzone extends React.Component {
4850 document . addEventListener ( 'dragover' , Dropzone . onDocumentDragOver , false )
4951 document . addEventListener ( 'drop' , this . onDocumentDrop , false )
5052 }
53+ this . fileInputEl . addEventListener ( 'click' , this . onInputElementClick , false )
5154 // Tried implementing addEventListener, but didn't work out
5255 document . body . onfocus = this . onFileDialogCancel
5356 }
@@ -58,6 +61,7 @@ class Dropzone extends React.Component {
5861 document . removeEventListener ( 'dragover' , Dropzone . onDocumentDragOver )
5962 document . removeEventListener ( 'drop' , this . onDocumentDrop )
6063 }
64+ this . fileInputEl . removeEventListener ( 'click' , this . onInputElementClick , false )
6165 // Can be replaced with removeEventListener, if addEventListener works
6266 document . body . onfocus = null
6367 }
@@ -196,6 +200,13 @@ class Dropzone extends React.Component {
196200 }
197201 }
198202
203+ onInputElementClick ( evt ) {
204+ evt . stopPropagation ( )
205+ if ( this . props . inputProps && this . props . inputProps . onClick ) {
206+ this . props . inputProps . onClick ( )
207+ }
208+ }
209+
199210 onFileDialogCancel ( ) {
200211 // timeout will not recognize context of this method
201212 const { onFileDialogCancel } = this . props
@@ -219,6 +230,10 @@ class Dropzone extends React.Component {
219230 this . node = ref
220231 }
221232
233+ setRefs ( ref ) {
234+ this . fileInputEl = ref
235+ }
236+
222237 fileMatchSize ( file ) {
223238 return file . size <= this . props . maxSize && file . size >= this . props . minSize
224239 }
@@ -323,7 +338,7 @@ class Dropzone extends React.Component {
323338 type : 'file' ,
324339 style : { display : 'none' } ,
325340 multiple : supportMultiple && multiple ,
326- ref : el => this . fileInputEl = el , // eslint-disable-line
341+ ref : this . setRefs ,
327342 onChange : this . onDrop
328343 }
329344
0 commit comments