]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(runtime-dom): enable set form attr to null on form-elements (#2840) (#2849)
authorluwuer <html6@foxmail.com>
Wed, 3 Feb 2021 18:11:09 +0000 (02:11 +0800)
committerGitHub <noreply@github.com>
Wed, 3 Feb 2021 18:11:09 +0000 (19:11 +0100)
Co-authored-by: Eduardo San Martin Morote <posva@users.noreply.github.com>
Co-authored-by: Thorsten Lünborg <t.luenborg@googlemail.com>
packages/runtime-dom/__tests__/patchProps.spec.ts
packages/runtime-dom/src/patchProp.ts
packages/shared/src/domTagConfig.ts

index 687b2b7905652eaf8cc8e81ea4af6be74a23b731..962d55e882b78fb16e73a29783571a412fad2c1e 100644 (file)
@@ -145,5 +145,8 @@ describe('runtime-dom: props patching', () => {
     // non existant element
     expect(el.form).toBe(null)
     expect(el.getAttribute('form')).toBe('foo')
+    // remove attribute
+    patchProp(el, 'form', 'foo', null)
+    expect(el.getAttribute('form')).toBe(null)
   })
 })
index 91f6ed526dc357c1561390f8c0922b1bc2bc0a23..848ee160a8b023e8ba98475607e51dda4e38dcb7 100644 (file)
@@ -3,7 +3,13 @@ import { patchStyle } from './modules/style'
 import { patchAttr } from './modules/attrs'
 import { patchDOMProp } from './modules/props'
 import { patchEvent } from './modules/events'
-import { isOn, isString, isFunction, isModelListener } from '@vue/shared'
+import {
+  isOn,
+  isString,
+  isFunction,
+  isModelListener,
+  isFormTag
+} from '@vue/shared'
 import { RendererOptions } from '@vue/runtime-core'
 
 const nativeOnRE = /^on[a-z]/
@@ -93,9 +99,9 @@ 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') {
+  // #1787, #2840 the form property is readonly and can only be set as an
+  // attribute using a string value
+  if (key === 'form' && isFormTag(el.tagName)) {
     return false
   }
 
index bbacdc12535db32f4ad6d9289171bc11b85697e3..d18e392b55b2d88d8d1511e3fa69cb09726b78dd 100644 (file)
@@ -30,6 +30,11 @@ const SVG_TAGS =
 const VOID_TAGS =
   'area,base,br,col,embed,hr,img,input,link,meta,param,source,track,wbr'
 
+const FORM_TAGS =
+  'button,datalist,fieldset,input,keygen,label,legend,meter,optgroup,option,' +
+  'output,progress,select,textarea'
+
 export const isHTMLTag = /*#__PURE__*/ makeMap(HTML_TAGS)
 export const isSVGTag = /*#__PURE__*/ makeMap(SVG_TAGS)
 export const isVoidTag = /*#__PURE__*/ makeMap(VOID_TAGS)
+export const isFormTag = /*#__PURE__*/ makeMap(FORM_TAGS, true)