Commit 917ce43c authored by Leopoldthecoder's avatar Leopoldthecoder Committed by 杨奕

Select: optimize onOptionDestroy

parent f23629ac
...@@ -48,7 +48,7 @@ export default { ...@@ -48,7 +48,7 @@ export default {
this.navigateOptions(direction); this.navigateOptions(direction);
} }
} }
this.$nextTick(() => this.scrollToOption(this.hoverOption.$el)); this.$nextTick(() => this.scrollToOption(this.hoverOption));
} }
} }
}; };
...@@ -143,14 +143,13 @@ ...@@ -143,14 +143,13 @@
this.select.cachedOptions.push(this); this.select.cachedOptions.push(this);
this.select.optionsCount++; this.select.optionsCount++;
this.select.filteredOptionsCount++; this.select.filteredOptionsCount++;
this.index = this.select.options.indexOf(this);
this.$on('queryChange', this.queryChange); this.$on('queryChange', this.queryChange);
this.$on('handleGroupDisabled', this.handleGroupDisabled); this.$on('handleGroupDisabled', this.handleGroupDisabled);
}, },
beforeDestroy() { beforeDestroy() {
this.dispatch('ElSelect', 'onOptionDestroy', this); this.dispatch('ElSelect', 'onOptionDestroy', this.select.options.indexOf(this));
} }
}; };
</script> </script>
...@@ -336,7 +336,6 @@ ...@@ -336,7 +336,6 @@
methods: { methods: {
handleQueryChange(val) { handleQueryChange(val) {
if (this.previousQuery === val) return; if (this.previousQuery === val) return;
console.log(val);
this.previousQuery = val; this.previousQuery = val;
this.$nextTick(() => { this.$nextTick(() => {
if (this.visible) this.broadcast('ElSelectDropdown', 'updatePopper'); if (this.visible) this.broadcast('ElSelectDropdown', 'updatePopper');
...@@ -585,9 +584,6 @@ ...@@ -585,9 +584,6 @@
}, },
toggleMenu() { toggleMenu() {
if (this.filterable && this.query === '' && this.visible) {
return;
}
if (!this.disabled) { if (!this.disabled) {
this.visible = !this.visible; this.visible = !this.visible;
} }
...@@ -626,11 +622,10 @@ ...@@ -626,11 +622,10 @@
} }
}, },
onOptionDestroy(option) { onOptionDestroy(index) {
if (index > -1) {
this.optionsCount--; this.optionsCount--;
this.filteredOptionsCount--; this.filteredOptionsCount--;
let index = this.options.indexOf(option);
if (index > -1) {
this.options.splice(index, 1); this.options.splice(index, 1);
} }
}, },
......
...@@ -479,16 +479,11 @@ describe('Select', () => { ...@@ -479,16 +479,11 @@ describe('Select', () => {
select.$el.querySelector('input').focus(); select.$el.querySelector('input').focus();
select.query = '3'; select.query = '3';
select.handleQueryChange('3'); select.handleQueryChange('3');
setTimeout(() => { select.selectOption();
const enterKey = document.createEvent('Events');
enterKey.initEvent('keydown', true, true);
enterKey.keyCode = 13;
select.$el.querySelector('input').dispatchEvent(enterKey);
setTimeout(() => { setTimeout(() => {
expect(select.value).to.equal('3'); expect(select.value).to.equal('3');
done(); done();
}, 10); }, 10);
}, 10); // wait for async filterMethod
}, 10); }, 10);
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment