fix(runtime-dom): enable set form attr to null on form-elements (#2840) (#2849)

Co-authored-by: Eduardo San Martin Morote <posva@users.noreply.github.com>
Co-authored-by: Thorsten Lünborg <t.luenborg@googlemail.com>
This commit is contained in:
luwuer 2021-02-04 02:11:09 +08:00 committed by GitHub
parent 6b0a549725
commit f262438073
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 4 deletions

View File

@ -145,5 +145,8 @@ describe('runtime-dom: props patching', () => {
// non existant element // non existant element
expect(el.form).toBe(null) expect(el.form).toBe(null)
expect(el.getAttribute('form')).toBe('foo') expect(el.getAttribute('form')).toBe('foo')
// remove attribute
patchProp(el, 'form', 'foo', null)
expect(el.getAttribute('form')).toBe(null)
}) })
}) })

View File

@ -3,7 +3,13 @@ import { patchStyle } from './modules/style'
import { patchAttr } from './modules/attrs' import { patchAttr } from './modules/attrs'
import { patchDOMProp } from './modules/props' import { patchDOMProp } from './modules/props'
import { patchEvent } from './modules/events' 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' import { RendererOptions } from '@vue/runtime-core'
const nativeOnRE = /^on[a-z]/ const nativeOnRE = /^on[a-z]/
@ -93,9 +99,9 @@ function shouldSetAsProp(
return false return false
} }
// #1787 form as an attribute must be a string, while it accepts an Element as // #1787, #2840 the form property is readonly and can only be set as an
// a prop // attribute using a string value
if (key === 'form' && typeof value === 'string') { if (key === 'form' && isFormTag(el.tagName)) {
return false return false
} }

View File

@ -30,6 +30,11 @@ const SVG_TAGS =
const VOID_TAGS = const VOID_TAGS =
'area,base,br,col,embed,hr,img,input,link,meta,param,source,track,wbr' '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 isHTMLTag = /*#__PURE__*/ makeMap(HTML_TAGS)
export const isSVGTag = /*#__PURE__*/ makeMap(SVG_TAGS) export const isSVGTag = /*#__PURE__*/ makeMap(SVG_TAGS)
export const isVoidTag = /*#__PURE__*/ makeMap(VOID_TAGS) export const isVoidTag = /*#__PURE__*/ makeMap(VOID_TAGS)
export const isFormTag = /*#__PURE__*/ makeMap(FORM_TAGS, true)