This repository was archived by the owner on Aug 23, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +45
-4
lines changed Expand file tree Collapse file tree 2 files changed +45
-4
lines changed Original file line number Diff line number Diff line change @@ -33,19 +33,26 @@ function isEvent(event) {
33
33
}
34
34
35
35
function getEventValue ( event ) {
36
- if ( ! event . target ) {
36
+ const { target } = event ;
37
+
38
+ if ( ! target ) {
37
39
if ( ! event . nativeEvent ) {
38
40
return undefined ;
39
41
}
40
42
41
43
return event . nativeEvent . text ;
42
44
}
43
45
44
- if ( event . target . multiple ) {
45
- return [ ...event . target . selectedOptions ] . map ( option => option . value ) ;
46
+ if ( target . type === 'file' ) {
47
+ return [ ...target . files ]
48
+ || ( target . dataTransfer && [ ...target . dataTransfer . files ] ) ;
49
+ }
50
+
51
+ if ( target . multiple ) {
52
+ return [ ...target . selectedOptions ] . map ( option => option . value ) ;
46
53
}
47
54
48
- return event . target . value ;
55
+ return target . value ;
49
56
}
50
57
51
58
function getValue ( value ) {
Original file line number Diff line number Diff line change @@ -454,6 +454,40 @@ describe('<Field /> component', () => {
454
454
} ) ;
455
455
} ) ;
456
456
457
+ describe ( 'with <input type="file" />' , ( ) => {
458
+ const store = applyMiddleware ( thunk ) ( createStore ) ( combineReducers ( {
459
+ testForm : formReducer ( 'test' ) ,
460
+ test : modelReducer ( 'test' , { foo : [ ] } ) ,
461
+ } ) ) ;
462
+
463
+ const field = TestUtils . renderIntoDocument (
464
+ < Provider store = { store } >
465
+ < Field model = "test.foo" >
466
+ < input type = "file" />
467
+ </ Field >
468
+ </ Provider >
469
+ ) ;
470
+
471
+ const input = TestUtils . findRenderedDOMComponentWithTag ( field , 'input' ) ;
472
+
473
+ TestUtils . Simulate . change ( input , {
474
+ target : {
475
+ type : 'file' ,
476
+ files : [
477
+ { name : 'first.jpg' } ,
478
+ { name : 'second.jpg' } ,
479
+ ] ,
480
+ } ,
481
+ } ) ;
482
+
483
+ assert . deepEqual (
484
+ store . getState ( ) . test . foo ,
485
+ [
486
+ { name : 'first.jpg' } ,
487
+ { name : 'second.jpg' } ,
488
+ ] ) ;
489
+ } ) ;
490
+
457
491
describe ( 'with <select>' , ( ) => {
458
492
const store = applyMiddleware ( thunk ) ( createStore ) ( combineReducers ( {
459
493
testForm : formReducer ( 'test' ) ,
You can’t perform that action at this time.
0 commit comments