Browse Source

Select: fix filterable group bug, fixed #1678 (#1679)

杨奕 8 years ago
parent
commit
0ccd537cc8
2 changed files with 23 additions and 1 deletions
  1. 21 1
      packages/select/src/option-group.vue
  2. 2 0
      packages/select/src/select.vue

+ 21 - 1
packages/select/src/option-group.vue

@@ -1,6 +1,6 @@
 <template>
   <ul class="el-select-group__wrap">
-    <li class="el-select-group__title">{{ label }}</li>
+    <li class="el-select-group__title" v-show="visible">{{ label }}</li>
     <li>
       <ul class="el-select-group">
         <slot></slot>
@@ -17,6 +17,8 @@
 
     name: 'el-option-group',
 
+    componentName: 'ElOptionGroup',
+
     props: {
       label: String,
       disabled: {
@@ -25,12 +27,30 @@
       }
     },
 
+    data() {
+      return {
+        visible: true
+      };
+    },
+
     watch: {
       disabled(val) {
         this.broadcast('ElOption', 'handleGroupDisabled', val);
       }
     },
 
+    methods: {
+      queryChange() {
+        this.visible = this.$children &&
+          Array.isArray(this.$children) &&
+          this.$children.some(option => option.visible === true);
+      }
+    },
+
+    created() {
+      this.$on('queryChange', this.queryChange);
+    },
+
     mounted() {
       if (this.disabled) {
         this.broadcast('ElOption', 'handleGroupDisabled', this.disabled);

+ 2 - 0
packages/select/src/select.vue

@@ -228,9 +228,11 @@
           this.broadcast('ElOption', 'resetIndex');
         } else if (typeof this.filterMethod === 'function') {
           this.filterMethod(val);
+          this.broadcast('ElOptionGroup', 'queryChange');
         } else {
           this.filteredOptionsCount = this.optionsCount;
           this.broadcast('ElOption', 'queryChange', val);
+          this.broadcast('ElOptionGroup', 'queryChange');
         }
       },