diff --git a/packages/runtime-dom/__tests__/patchProps.spec.ts b/packages/runtime-dom/__tests__/patchProps.spec.ts index 24760695040..9a324970cc9 100644 --- a/packages/runtime-dom/__tests__/patchProps.spec.ts +++ b/packages/runtime-dom/__tests__/patchProps.spec.ts @@ -234,12 +234,29 @@ describe('runtime-dom: props patching', () => { expect(el.getAttribute('x')).toBe('2') }) - test('input with size', () => { + test('input with size (number property)', () => { const el = document.createElement('input') patchProp(el, 'size', null, 100) expect(el.size).toBe(100) patchProp(el, 'size', 100, null) expect(el.getAttribute('size')).toBe(null) + expect('Failed setting prop "size" on ').toHaveBeenWarnedLast() + }) + + test('select with type (string property)', () => { + const el = document.createElement('select') + patchProp(el, 'type', null, 'test') + expect(el.type).toBe('select-one') + expect('Failed setting prop "type" on ' + ).toHaveBeenWarnedLast() }) test('patch value for select', () => { diff --git a/packages/runtime-dom/src/modules/props.ts b/packages/runtime-dom/src/modules/props.ts index 5092911e44a..591f8caa7d0 100644 --- a/packages/runtime-dom/src/modules/props.ts +++ b/packages/runtime-dom/src/modules/props.ts @@ -51,51 +51,48 @@ export function patchDOMProp( return } + let needRemove = false if (value === '' || value == null) { const type = typeof el[key] if (type === 'boolean') { // e.g. try { el[key] = value } catch (e: any) { @@ -107,4 +104,5 @@ export function patchDOMProp( ) } } + needRemove && el.removeAttribute(key) }