mirror of https://github.com/ElemeFE/element
Select: optimize onOptionDestroy
parent
f23629ac43
commit
917ce43cad
|
@ -48,7 +48,7 @@ export default {
|
|||
this.navigateOptions(direction);
|
||||
}
|
||||
}
|
||||
this.$nextTick(() => this.scrollToOption(this.hoverOption.$el));
|
||||
this.$nextTick(() => this.scrollToOption(this.hoverOption));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
},
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue