File tree Expand file tree Collapse file tree 2 files changed +33
-1
lines changed
src/renderers/dom/client/wrappers Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -67,7 +67,11 @@ var ReactDOMInput = {
67
67
var value = LinkedValueUtils . getValue ( props ) ;
68
68
var checked = LinkedValueUtils . getChecked ( props ) ;
69
69
70
- var nativeProps = assign ( { } , props , {
70
+ var nativeProps = assign ( {
71
+ // Make sure we set .type before any other properties (setting .value
72
+ // before .type means .value is lost in IE11 and below)
73
+ type : undefined ,
74
+ } , props , {
71
75
defaultChecked : undefined ,
72
76
defaultValue : undefined ,
73
77
value : value != null ? value : inst . _wrapperState . initialValue ,
Original file line number Diff line number Diff line change @@ -414,4 +414,32 @@ describe('ReactDOMInput', function() {
414
414
ReactTestUtils . renderIntoDocument ( < input type = "text" value = { null } /> ) ;
415
415
expect ( console . error . argsForCall . length ) . toBe ( 1 ) ;
416
416
} ) ;
417
+
418
+ it ( 'sets type before value always' , function ( ) {
419
+ var log = [ ] ;
420
+ var originalCreateElement = document . createElement ;
421
+ spyOn ( document , 'createElement' ) . andCallFake ( function ( type ) {
422
+ var el = originalCreateElement . apply ( this , arguments ) ;
423
+ if ( type === 'input' ) {
424
+ Object . defineProperty ( el , 'value' , {
425
+ get : function ( ) { } ,
426
+ set : function ( ) {
427
+ log . push ( 'set value' ) ;
428
+ } ,
429
+ } ) ;
430
+ spyOn ( el , 'setAttribute' ) . andCallFake ( function ( name , value ) {
431
+ log . push ( 'set ' + name ) ;
432
+ } ) ;
433
+ }
434
+ return el ;
435
+ } ) ;
436
+
437
+ ReactTestUtils . renderIntoDocument ( < input value = "hi" type = "radio" /> ) ;
438
+ // Setting value before type does bad things. Make sure we set type first.
439
+ expect ( log ) . toEqual ( [
440
+ 'set data-reactroot' ,
441
+ 'set type' ,
442
+ 'set value' ,
443
+ ] ) ;
444
+ } ) ;
417
445
} ) ;
You can’t perform that action at this time.
0 commit comments