From d6caddd722df88ae2947bb89c862ce216fbb6eb5 Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Wed, 5 Aug 2020 19:31:15 +0200 Subject: [PATCH] fix: patch form as an attribute Close #1787 --- packages/runtime-dom/__tests__/patchProps.spec.ts | 8 ++++++++ packages/runtime-dom/src/patchProp.ts | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/packages/runtime-dom/__tests__/patchProps.spec.ts b/packages/runtime-dom/__tests__/patchProps.spec.ts index f8c3c06b344..0501e04d01b 100644 --- a/packages/runtime-dom/__tests__/patchProps.spec.ts +++ b/packages/runtime-dom/__tests__/patchProps.spec.ts @@ -121,4 +121,12 @@ describe('runtime-dom: props patching', () => { patchProp(el, 'id', null, '') expect(el.hasAttribute('id')).toBe(true) }) + + test('form attribute', () => { + const el = document.createElement('input') + patchProp(el, 'form', null, 'foo') + // non existant element + expect(el.form).toBe(null) + expect(el.getAttribute('form')).toBe('foo') + }) }) diff --git a/packages/runtime-dom/src/patchProp.ts b/packages/runtime-dom/src/patchProp.ts index a7c27730981..91f6ed526dc 100644 --- a/packages/runtime-dom/src/patchProp.ts +++ b/packages/runtime-dom/src/patchProp.ts @@ -93,6 +93,12 @@ function shouldSetAsProp( return false } + // #1787 form as an attribute must be a string, while it accepts an Element as + // a prop + if (key === 'form' && typeof value === 'string') { + return false + } + // #1526 must be set as attribute if (key === 'list' && el.tagName === 'INPUT') { return false