Skip to content

Commit 89b2f92

Browse files
authored
fix(runtime-dom): fix option element value patching edge case (#4959)
fix #4956
1 parent 3c449cd commit 89b2f92

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

packages/runtime-dom/__tests__/patchProps.spec.ts

+3
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,12 @@ describe('runtime-dom: props patching', () => {
2929
// so we need to add tests for other elements
3030
test('value for non-text input', () => {
3131
const el = document.createElement('option')
32+
el.textContent = 'foo' // #4956
3233
patchProp(el, 'value', null, 'foo')
34+
expect(el.getAttribute('value')).toBe('foo')
3335
expect(el.value).toBe('foo')
3436
patchProp(el, 'value', null, null)
37+
el.textContent = ''
3538
expect(el.value).toBe('')
3639
// #3475
3740
expect(el.getAttribute('value')).toBe(null)

packages/runtime-dom/src/modules/props.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,13 @@ export function patchDOMProp(
3131
// non-string values will be stringified.
3232
el._value = value
3333
const newValue = value == null ? '' : value
34-
if (el.value !== newValue) {
34+
if (
35+
el.value !== newValue ||
36+
// #4956: always set for OPTION elements because its value falls back to
37+
// textContent if no value attribute is present. And setting .value for
38+
// OPTION has no side effect
39+
el.tagName === 'OPTION'
40+
) {
3541
el.value = newValue
3642
}
3743
if (value == null) {

0 commit comments

Comments
 (0)