Skip to content

Commit

Permalink
fix(runtime-dom): avoid unset option's value
Browse files Browse the repository at this point in the history
  • Loading branch information
Doctor-wu committed Feb 27, 2024
1 parent 89de26c commit 1661fa8
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/runtime-dom/src/modules/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,17 @@ export function patchDOMProp(
// custom elements may use _value internally
!tag.includes('-')
) {
const mounted = '_value' in el
// store value as _value as well since
// non-string values will be stringified.
el._value = value
// #4956: <option> value will fallback to its text content so we need to
// compare against its attribute value instead.
const oldValue =
tag === 'OPTION' ? el.getAttribute('value') || '' : el.value
let oldValue = el.value
if (tag === 'OPTION') {
const attrValue = el.getAttribute('value')
oldValue = mounted ? attrValue || '' : attrValue
}
const newValue = value == null ? '' : value
if (oldValue !== newValue) {
el.value = newValue
Expand Down

0 comments on commit 1661fa8

Please sign in to comment.