Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Feb 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/runtime-dom/__tests__/patchProps.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})
14 changes: 10 additions & 4 deletions packages/runtime-dom/src/patchProp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]/
Expand Down Expand Up @@ -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)) {
luwuer marked this conversation as resolved.
Show resolved Hide resolved
return false
}

Expand Down
5 changes: 5 additions & 0 deletions packages/shared/src/domTagConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)