File tree 2 files changed +17
-10
lines changed
2 files changed +17
-10
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,14 @@ describe('runtime-dom: props patching', () => {
24
24
patchProp ( el , 'value' , null , obj )
25
25
expect ( el . value ) . toBe ( obj . toString ( ) )
26
26
expect ( ( el as any ) . _value ) . toBe ( obj )
27
+
28
+ const option = document . createElement ( 'option' )
29
+ patchProp ( option , 'textContent' , null , 'foo' )
30
+ expect ( option . value ) . toBe ( 'foo' )
31
+ expect ( option . getAttribute ( 'value' ) ) . toBe ( null )
32
+ patchProp ( option , 'value' , null , 'foo' )
33
+ expect ( option . value ) . toBe ( 'foo' )
34
+ expect ( option . getAttribute ( 'value' ) ) . toBe ( 'foo' )
27
35
} )
28
36
29
37
test ( 'value for custom elements' , ( ) => {
Original file line number Diff line number Diff line change @@ -26,23 +26,22 @@ export function patchDOMProp(
26
26
return
27
27
}
28
28
29
+ const tag = el . tagName
30
+
29
31
if (
30
32
key === 'value' &&
31
- el . tagName !== 'PROGRESS' &&
33
+ tag !== 'PROGRESS' &&
32
34
// custom elements may use _value internally
33
- ! el . tagName . includes ( '-' )
35
+ ! tag . includes ( '-' )
34
36
) {
35
37
// store value as _value as well since
36
38
// non-string values will be stringified.
37
39
el . _value = value
40
+ // #4956: <option> value will fallback to its text content so we need to
41
+ // compare against its attribute value instead.
42
+ const oldValue = tag === 'OPTION' ? el . getAttribute ( 'value' ) : el . value
38
43
const newValue = value == null ? '' : value
39
- if (
40
- el . value !== newValue ||
41
- // #4956: always set for OPTION elements because its value falls back to
42
- // textContent if no value attribute is present. And setting .value for
43
- // OPTION has no side effect
44
- el . tagName === 'OPTION'
45
- ) {
44
+ if ( oldValue !== newValue ) {
46
45
el . value = newValue
47
46
}
48
47
if ( value == null ) {
@@ -98,7 +97,7 @@ export function patchDOMProp(
98
97
// do not warn if value is auto-coerced from nullish values
99
98
if ( __DEV__ && ! needRemove ) {
100
99
warn (
101
- `Failed setting prop "${ key } " on <${ el . tagName . toLowerCase ( ) } >: ` +
100
+ `Failed setting prop "${ key } " on <${ tag . toLowerCase ( ) } >: ` +
102
101
`value ${ value } is invalid.` ,
103
102
e
104
103
)
You can’t perform that action at this time.
0 commit comments