Select: optimize onOptionDestroy

pull/6325/head
Leopoldthecoder 2017-07-30 11:20:44 +08:00 committed by 杨奕
parent f23629ac43
commit 917ce43cad
4 changed files with 9 additions and 20 deletions

View File

@ -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));
} }
} }
}; };

View File

@ -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>

View File

@ -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 @@
}, },
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 @@
} }
}, },
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);
} }
}, },

View File

@ -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);
}); });