Skip to content

Commit 441c236

Browse files
committedJul 6, 2020
fix(runtime-dom): should set <input list="..."> as attribute
fix #1526
1 parent 31e37b4 commit 441c236

File tree

1 file changed

+44
-20
lines changed

1 file changed

+44
-20
lines changed
 

‎packages/runtime-dom/src/patchProp.ts

+44-20
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { patchDOMProp } from './modules/props'
55
import { patchEvent } from './modules/events'
66
import { isOn, isString, isFunction } from '@vue/shared'
77
import { RendererOptions } from '@vue/runtime-core'
8+
import { chdir } from 'process'
Has a conversation. Original line has a conversation.
89

910
const nativeOnRE = /^on[a-z]/
1011

@@ -38,26 +39,7 @@ export const patchProp: DOMRendererOptions['patchProp'] = (
3839
if (!key.startsWith('onUpdate:')) {
3940
patchEvent(el, key, prevValue, nextValue, parentComponent)
4041
}
41-
} else if (
42-
// spellcheck and draggable are numerated attrs, however their
43-
// corresponding DOM properties are actually booleans - this leads to
44-
// setting it with a string "false" value leading it to be coerced to
45-
// `true`, so we need to always treat them as attributes.
46-
// Note that `contentEditable` doesn't have this problem: its DOM
47-
// property is also enumerated string values.
48-
key !== 'spellcheck' &&
49-
key !== 'draggable' &&
50-
(isSVG
51-
? // most keys must be set as attribute on svg elements to work
52-
// ...except innerHTML
53-
key === 'innerHTML' ||
54-
// or native onclick with function values
55-
(key in el && nativeOnRE.test(key) && isFunction(nextValue))
56-
: // for normal html elements, set as a property if it exists
57-
key in el &&
58-
// except native onclick with string values
59-
!(nativeOnRE.test(key) && isString(nextValue)))
60-
) {
42+
} else if (shouldSetAsProp(el, key, nextValue, isSVG)) {
6143
patchDOMProp(
6244
el,
6345
key,
@@ -82,3 +64,45 @@ export const patchProp: DOMRendererOptions['patchProp'] = (
8264
break
8365
}
8466
}
67+
68+
function shouldSetAsProp(
69+
el: Element,
70+
key: string,
71+
value: unknown,
72+
isSVG: boolean
73+
) {
74+
if (isSVG) {
75+
// most keys must be set as attribute on svg elements to work
76+
// ...except innerHTML
77+
if (key === 'innerHTML') {
78+
return true
79+
}
80+
// or native onclick with function values
81+
if (key in el && nativeOnRE.test(key) && isFunction(value)) {
82+
return true
83+
}
84+
return false
85+
}
86+
87+
// spellcheck and draggable are numerated attrs, however their
88+
// corresponding DOM properties are actually booleans - this leads to
89+
// setting it with a string "false" value leading it to be coerced to
90+
// `true`, so we need to always treat them as attributes.
91+
// Note that `contentEditable` doesn't have this problem: its DOM
92+
// property is also enumerated string values.
93+
if (key === 'spellcheck' || key === 'draggable') {
94+
return false
95+
}
96+
97+
// #1526 <input list> must be set as attribute
98+
if (key === 'list' && el.tagName === 'INPUT') {
99+
return false
100+
}
101+
102+
// native onclick with string value, must be set as attribute
103+
if (nativeOnRE.test(key) && isString(value)) {
104+
return false
105+
}
106+
107+
return key in el
108+
}

0 commit comments

Comments
 (0)
Please sign in to comment.