Преглед изворни кода

Merge pull request #2186 from Leopoldthecoder/select-fix

Select: fix allowCreate bug
baiyaaaaa пре 8 година
родитељ
комит
9773276fee
2 измењених фајлова са 20 додато и 3 уклоњено
  1. 2 2
      packages/select/src/option.vue
  2. 18 1
      packages/select/src/select.vue

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

@@ -88,10 +88,10 @@
 
     watch: {
       currentLabel() {
-        this.dispatch('ElSelect', 'setSelected');
+        if (!this.created) this.dispatch('ElSelect', 'setSelected');
       },
       value() {
-        this.dispatch('ElSelect', 'setSelected');
+        if (!this.created) this.dispatch('ElSelect', 'setSelected');
       }
     },
 

+ 18 - 1
packages/select/src/select.vue

@@ -98,6 +98,7 @@
   import { addClass, removeClass, hasClass } from 'element-ui/src/utils/dom';
   import { addResizeListener, removeResizeListener } from 'element-ui/src/utils/resize-event';
   import { t } from 'element-ui/src/locale';
+  import merge from 'element-ui/src/utils/merge';
   const sizeMap = {
     'large': 42,
     'small': 30,
@@ -191,6 +192,8 @@
       return {
         options: [],
         cachedOptions: [],
+        createdOption: null,
+        createdSelected: false,
         selected: this.multiple ? [] : {},
         isSelect: true,
         inputLength: 20,
@@ -276,7 +279,12 @@
           if (!this.multiple) {
             this.getOverflows();
             if (this.selected) {
-              this.selectedLabel = this.selected.currentLabel;
+              if (this.filterable && this.allowCreate &&
+                this.createdSelected && this.createdOption) {
+                this.selectedLabel = this.createdOption.currentLabel;
+              } else {
+                this.selectedLabel = this.selected.currentLabel;
+              }
               if (this.filterable) this.query = this.selectedLabel;
             }
           }
@@ -371,6 +379,12 @@
       setSelected() {
         if (!this.multiple) {
           let option = this.getOption(this.value);
+          if (option.created) {
+            this.createdOption = merge({}, option);
+            this.createdSelected = true;
+          } else {
+            this.createdSelected = false;
+          }
           this.selectedLabel = option.currentLabel;
           this.selected = option;
           return;
@@ -382,6 +396,9 @@
           });
         }
         this.selected = result;
+        this.$nextTick(() => {
+          this.resetInputHeight();
+        });
       },
 
       handleIconClick(event) {