Skip to content

Commit f9bef75

Browse files
committed
fix select multiple first option auto-selected in Chrome/FF (fix #3852)
1 parent 74e4e11 commit f9bef75

File tree

1 file changed

+10
-1
lines changed
  • src/platforms/web/runtime/modules

1 file changed

+10
-1
lines changed

src/platforms/web/runtime/modules/attrs.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@ function setAttr (el: Element, key: string, value: any) {
6868
}
6969

7070
export default {
71-
create: updateAttrs,
71+
create: function initAttrs (_: VNodeWithData, vnode: VNodeWithData) {
72+
updateAttrs(_, vnode)
73+
// #3852: if the "multiple" attribute is added to a <select> element
74+
// when the children options have already been appended, Chrome/Firefox
75+
// auto-selects the first option.
76+
const el: any = vnode.elm
77+
if (vnode.tag === 'select' && el.multiple) {
78+
el.options[0] && (el.options[0].selected = false)
79+
}
80+
},
7281
update: updateAttrs
7382
}

0 commit comments

Comments
 (0)