File tree 3 files changed +43
-1
lines changed
3 files changed +43
-1
lines changed Original file line number Diff line number Diff line change @@ -459,6 +459,15 @@ function processAttrs (el) {
459
459
}
460
460
}
461
461
addAttr ( el , name , JSON . stringify ( value ) )
462
+ // #4530 also bind special attributes as props even if they are static
463
+ // so that patches between dynamic/static are consistent
464
+ if ( platformMustUseProp ( el . tag , name ) ) {
465
+ if ( name === 'value' ) {
466
+ addProp ( el , name , JSON . stringify ( value ) )
467
+ } else {
468
+ addProp ( el , name , 'true' )
469
+ }
470
+ }
462
471
}
463
472
}
464
473
}
Original file line number Diff line number Diff line change @@ -391,7 +391,7 @@ describe('parser', () => {
391
391
392
392
it ( 'literal attribute' , ( ) => {
393
393
// basic
394
- const ast1 = parse ( '<input type="text" name="field1" value="hello world">' , baseOptions )
394
+ const ast1 = parse ( '<input type="text" name="field1" value="hello world" checked >' , baseOptions )
395
395
expect ( ast1 . attrsList [ 0 ] . name ) . toBe ( 'type' )
396
396
expect ( ast1 . attrsList [ 0 ] . value ) . toBe ( 'text' )
397
397
expect ( ast1 . attrsList [ 1 ] . name ) . toBe ( 'name' )
@@ -407,6 +407,13 @@ describe('parser', () => {
407
407
expect ( ast1 . attrs [ 1 ] . value ) . toBe ( '"field1"' )
408
408
expect ( ast1 . attrs [ 2 ] . name ) . toBe ( 'value' )
409
409
expect ( ast1 . attrs [ 2 ] . value ) . toBe ( '"hello world"' )
410
+ expect ( ast1 . attrs [ 3 ] . name ) . toBe ( 'checked' )
411
+ expect ( ast1 . attrs [ 3 ] . value ) . toBe ( '""' )
412
+ // also bind speicals as props
413
+ expect ( ast1 . props [ 0 ] . name ) . toBe ( 'value' )
414
+ expect ( ast1 . props [ 0 ] . value ) . toBe ( '"hello world"' )
415
+ expect ( ast1 . props [ 1 ] . name ) . toBe ( 'checked' )
416
+ expect ( ast1 . props [ 1 ] . value ) . toBe ( 'true' )
410
417
// interpolation warning
411
418
parse ( '<input type="text" name="field1" value="{{msg}}">' , baseOptions )
412
419
expect ( 'Interpolation inside attributes has been removed' ) . toHaveBeenWarned ( )
Original file line number Diff line number Diff line change @@ -114,4 +114,30 @@ describe('vdom patch: edge cases', () => {
114
114
} )
115
115
. then ( done )
116
116
} )
117
+
118
+ // #4530
119
+ it ( 'should not reset value when patching bewteen dyanmic/static bindings' , done => {
120
+ const vm = new Vue ( {
121
+ data : { ok : true } ,
122
+ template : `
123
+ <div>
124
+ <input v-if="ok" value="a">
125
+ <input v-else :value="'b'">
126
+ <input v-if="ok" type="checkbox" checked>
127
+ <input v-else type="checkbox" :checked="false">
128
+ </div>
129
+ `
130
+ } ) . $mount ( )
131
+ expect ( vm . $el . children [ 0 ] . value ) . toBe ( 'a' )
132
+ expect ( vm . $el . children [ 1 ] . checked ) . toBe ( true )
133
+ vm . ok = false
134
+ waitForUpdate ( ( ) => {
135
+ expect ( vm . $el . children [ 0 ] . value ) . toBe ( 'b' )
136
+ expect ( vm . $el . children [ 1 ] . checked ) . toBe ( false )
137
+ vm . ok = true
138
+ } ) . then ( ( ) => {
139
+ expect ( vm . $el . children [ 0 ] . value ) . toBe ( 'a' )
140
+ expect ( vm . $el . children [ 1 ] . checked ) . toBe ( true )
141
+ } ) . then ( done )
142
+ } )
117
143
} )
You can’t perform that action at this time.
0 commit comments