From: linghaoSu Date: Mon, 8 May 2023 07:26:14 +0000 (+0800) Subject: fix(runtime-dom): check attribute value when setting option value (#8246) X-Git-Tag: v3.3.0-beta.5~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4495373d28d9fa4479eedd224adb16248ae0b9f4;p=thirdparty%2Fvuejs%2Fcore.git fix(runtime-dom): check attribute value when setting option value (#8246) fix #8227 --- diff --git a/packages/runtime-dom/__tests__/patchProps.spec.ts b/packages/runtime-dom/__tests__/patchProps.spec.ts index c49de1a155..88cf916252 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 1c1ad0c16f..cdf9d84cf5 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: