Parcourir la source

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

Evan You il y a 9 ans
Parent
commit
f9bef75a34
1 fichiers modifiés avec 10 ajouts et 1 suppressions
  1. 10 1
      src/platforms/web/runtime/modules/attrs.js

+ 10 - 1
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
 }