Quellcode durchsuchen

Select: optimize onOptionDestroy

Leopoldthecoder vor 8 Jahren
Ursprung
Commit
917ce43cad

+ 1 - 1
packages/select/src/navigation-mixin.js

@@ -48,7 +48,7 @@ export default {
           this.navigateOptions(direction);
         }
       }
-      this.$nextTick(() => this.scrollToOption(this.hoverOption.$el));
+      this.$nextTick(() => this.scrollToOption(this.hoverOption));
     }
   }
 };

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

@@ -143,14 +143,13 @@
       this.select.cachedOptions.push(this);
       this.select.optionsCount++;
       this.select.filteredOptionsCount++;
-      this.index = this.select.options.indexOf(this);
 
       this.$on('queryChange', this.queryChange);
       this.$on('handleGroupDisabled', this.handleGroupDisabled);
     },
 
     beforeDestroy() {
-      this.dispatch('ElSelect', 'onOptionDestroy', this);
+      this.dispatch('ElSelect', 'onOptionDestroy', this.select.options.indexOf(this));
     }
   };
 </script>

+ 3 - 8
packages/select/src/select.vue

@@ -336,7 +336,6 @@
     methods: {
       handleQueryChange(val) {
         if (this.previousQuery === val) return;
-        console.log(val);
         this.previousQuery = val;
         this.$nextTick(() => {
           if (this.visible) this.broadcast('ElSelectDropdown', 'updatePopper');
@@ -585,9 +584,6 @@
       },
 
       toggleMenu() {
-        if (this.filterable && this.query === '' && this.visible) {
-          return;
-        }
         if (!this.disabled) {
           this.visible = !this.visible;
         }
@@ -626,11 +622,10 @@
         }
       },
 
-      onOptionDestroy(option) {
-        this.optionsCount--;
-        this.filteredOptionsCount--;
-        let index = this.options.indexOf(option);
+      onOptionDestroy(index) {
         if (index > -1) {
+          this.optionsCount--;
+          this.filteredOptionsCount--;
           this.options.splice(index, 1);
         }
       },

+ 4 - 9
test/unit/specs/select.spec.js

@@ -479,16 +479,11 @@ describe('Select', () => {
       select.$el.querySelector('input').focus();
       select.query = '3';
       select.handleQueryChange('3');
+      select.selectOption();
       setTimeout(() => {
-        const enterKey = document.createEvent('Events');
-        enterKey.initEvent('keydown', true, true);
-        enterKey.keyCode = 13;
-        select.$el.querySelector('input').dispatchEvent(enterKey);
-        setTimeout(() => {
-          expect(select.value).to.equal('3');
-          done();
-        }, 10);
-      }, 10);  // wait for async filterMethod
+        expect(select.value).to.equal('3');
+        done();
+      }, 10);
     }, 10);
   });