浏览代码

Select: fix a dropdown update bug (#1784)

杨奕 8 年之前
父节点
当前提交
92742dc56a
共有 2 个文件被更改,包括 16 次插入6 次删除
  1. 14 0
      packages/select/src/option.vue
  2. 2 6
      packages/select/src/select.vue

+ 14 - 0
packages/select/src/option.vue

@@ -86,6 +86,20 @@
       }
     },
 
+    watch: {
+      currentLabel() {
+        this.dispatch('ElSelect', 'setSelected');
+      },
+      value() {
+        this.dispatch('ElSelect', 'setSelected');
+      },
+      visible() {
+        this.$nextTick(() => {
+          this.dispatch('ElSelectDropdown', 'updatePopper');
+        });
+      }
+    },
+
     methods: {
       handleGroupDisabled(val) {
         this.groupDisabled = val;

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

@@ -194,7 +194,6 @@
         selectedLabel: '',
         hoverIndex: -1,
         query: '',
-        isForcedVisible: false,
         bottomOverflowBeforeHidden: 0,
         topOverflowBeforeHidden: 0,
         optionsAllDisabled: false,
@@ -231,10 +230,6 @@
         if (this.multiple && this.filterable) {
           this.resetInputHeight();
         }
-        if (this.isForcedVisible) {
-          this.isForcedVisible = false;
-          return;
-        }
         if (this.remote && typeof this.remoteMethod === 'function') {
           this.hoverIndex = -1;
           this.remoteMethod(val);
@@ -271,6 +266,7 @@
             this.getOverflows();
             if (this.selected) {
               this.selectedLabel = this.selected.currentLabel;
+              if (this.filterable) this.query = this.selectedLabel;
             }
           }
         } else {
@@ -282,7 +278,6 @@
               this.$refs.input.focus();
             } else {
               if (!this.remote) {
-                this.isForcedVisible = true;
                 this.broadcast('ElOption', 'queryChange', '');
               }
               this.broadcast('ElInput', 'inputSelect');
@@ -593,6 +588,7 @@
 
       this.$on('handleOptionClick', this.handleOptionSelect);
       this.$on('onOptionDestroy', this.onOptionDestroy);
+      this.$on('setSelected', this.setSelected);
     },
 
     mounted() {