Skip to content

Commit f262438

Browse files
luwuerposvaLinusBorg
authored
fix(runtime-dom): enable set form attr to null on form-elements (#2840) (#2849)
Co-authored-by: Eduardo San Martin Morote <[email protected]> Co-authored-by: Thorsten Lünborg <[email protected]>
1 parent 6b0a549 commit f262438

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

packages/runtime-dom/__tests__/patchProps.spec.ts

+3
Original file line numberDiff line numberDiff line change
@@ -145,5 +145,8 @@ describe('runtime-dom: props patching', () => {
145145
// non existant element
146146
expect(el.form).toBe(null)
147147
expect(el.getAttribute('form')).toBe('foo')
148+
// remove attribute
149+
patchProp(el, 'form', 'foo', null)
150+
expect(el.getAttribute('form')).toBe(null)
148151
})
149152
})

packages/runtime-dom/src/patchProp.ts

+10-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ import { patchStyle } from './modules/style'
33
import { patchAttr } from './modules/attrs'
44
import { patchDOMProp } from './modules/props'
55
import { patchEvent } from './modules/events'
6-
import { isOn, isString, isFunction, isModelListener } from '@vue/shared'
6+
import {
7+
isOn,
8+
isString,
9+
isFunction,
10+
isModelListener,
11+
isFormTag
12+
} from '@vue/shared'
713
import { RendererOptions } from '@vue/runtime-core'
814

915
const nativeOnRE = /^on[a-z]/
@@ -93,9 +99,9 @@ function shouldSetAsProp(
9399
return false
94100
}
95101

96-
// #1787 form as an attribute must be a string, while it accepts an Element as
97-
// a prop
98-
if (key === 'form' && typeof value === 'string') {
102+
// #1787, #2840 the form property is readonly and can only be set as an
103+
// attribute using a string value
104+
if (key === 'form' && isFormTag(el.tagName)) {
99105
return false
100106
}
101107

packages/shared/src/domTagConfig.ts

+5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ const SVG_TAGS =
3030
const VOID_TAGS =
3131
'area,base,br,col,embed,hr,img,input,link,meta,param,source,track,wbr'
3232

33+
const FORM_TAGS =
34+
'button,datalist,fieldset,input,keygen,label,legend,meter,optgroup,option,' +
35+
'output,progress,select,textarea'
36+
3337
export const isHTMLTag = /*#__PURE__*/ makeMap(HTML_TAGS)
3438
export const isSVGTag = /*#__PURE__*/ makeMap(SVG_TAGS)
3539
export const isVoidTag = /*#__PURE__*/ makeMap(VOID_TAGS)
40+
export const isFormTag = /*#__PURE__*/ makeMap(FORM_TAGS, true)

0 commit comments

Comments
 (0)