From 4495373d28d9fa4479eedd224adb16248ae0b9f4 Mon Sep 17 00:00:00 2001 From: linghaoSu Date: Mon, 8 May 2023 15:26:14 +0800 Subject: [PATCH] fix(runtime-dom): check attribute value when setting option value (#8246) fix #8227 --- .../runtime-dom/__tests__/patchProps.spec.ts | 8 ++++++++ packages/runtime-dom/src/modules/props.ts | 19 +++++++++---------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/packages/runtime-dom/__tests__/patchProps.spec.ts b/packages/runtime-dom/__tests__/patchProps.spec.ts index c49de1a155d..88cf916252b 100644 --- a/packages/runtime-dom/__tests__/patchProps.spec.ts +++ b/packages/runtime-dom/__tests__/patchProps.spec.ts @@ -24,6 +24,14 @@ describe('runtime-dom: props patching', () => { patchProp(el, 'value', null, obj) expect(el.value).toBe(obj.toString()) expect((el as any)._value).toBe(obj) + + const option = document.createElement('option') + patchProp(option, 'textContent', null, 'foo') + expect(option.value).toBe('foo') + expect(option.getAttribute('value')).toBe(null) + patchProp(option, 'value', null, 'foo') + expect(option.value).toBe('foo') + expect(option.getAttribute('value')).toBe('foo') }) test('value for custom elements', () => { diff --git a/packages/runtime-dom/src/modules/props.ts b/packages/runtime-dom/src/modules/props.ts index 1c1ad0c16f7..cdf9d84cf5d 100644 --- a/packages/runtime-dom/src/modules/props.ts +++ b/packages/runtime-dom/src/modules/props.ts @@ -26,23 +26,22 @@ export function patchDOMProp( return } + const tag = el.tagName + if ( key === 'value' && - el.tagName !== 'PROGRESS' && + tag !== 'PROGRESS' && // custom elements may use _value internally - !el.tagName.includes('-') + !tag.includes('-') ) { // store value as _value as well since // non-string values will be stringified. el._value = value + // #4956: