Browse Source

fix select multiple first option auto-selected in Chrome/FF (fix #3852)

dev
Evan You 8 years ago
parent
commit
f9bef75a34
  1. 11
      src/platforms/web/runtime/modules/attrs.js

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

@ -68,6 +68,15 @@ function setAttr (el: Element, key: string, value: any) {
}
export default {
create: updateAttrs,
create: function initAttrs (_: VNodeWithData, vnode: VNodeWithData) {
updateAttrs(_, vnode)
// #3852: if the "multiple" attribute is added to a <select> element
// when the children options have already been appended, Chrome/Firefox
// auto-selects the first option.
const el: any = vnode.elm
if (vnode.tag === 'select' && el.multiple) {
el.options[0] && (el.options[0].selected = false)
}
},
update: updateAttrs
}

Loading…
Cancel
Save