mirror of https://github.com/ElemeFE/element
[Bugfix] el-select multiple with vuex (#4226)
* Select: Fix Vuex compability when using multiple * Adding timeout for first click to allow input event to propagate before second click * Update select.vuepull/4547/head
parent
d3bf30b48c
commit
fcfda74543
|
@ -463,7 +463,9 @@
|
||||||
|
|
||||||
deletePrevTag(e) {
|
deletePrevTag(e) {
|
||||||
if (e.target.value.length <= 0 && !this.toggleLastOptionHitState()) {
|
if (e.target.value.length <= 0 && !this.toggleLastOptionHitState()) {
|
||||||
this.value.pop();
|
const value = this.value.slice();
|
||||||
|
value.pop();
|
||||||
|
this.$emit('input', value);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -506,26 +508,23 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
handleOptionSelect(option) {
|
handleOptionSelect(option) {
|
||||||
if (!this.multiple) {
|
if (this.multiple) {
|
||||||
this.$emit('input', option.value);
|
const value = this.value.slice();
|
||||||
this.visible = false;
|
const optionIndex = value.indexOf(option.value);
|
||||||
} else {
|
|
||||||
let optionIndex = -1;
|
|
||||||
this.value.forEach((item, index) => {
|
|
||||||
if (item === option.value) {
|
|
||||||
optionIndex = index;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (optionIndex > -1) {
|
if (optionIndex > -1) {
|
||||||
this.value.splice(optionIndex, 1);
|
value.splice(optionIndex, 1);
|
||||||
} else if (this.multipleLimit <= 0 || this.value.length < this.multipleLimit) {
|
} else if (this.multipleLimit <= 0 || value.length < this.multipleLimit) {
|
||||||
this.value.push(option.value);
|
value.push(option.value);
|
||||||
}
|
}
|
||||||
|
this.$emit('input', value);
|
||||||
if (option.created) {
|
if (option.created) {
|
||||||
this.query = '';
|
this.query = '';
|
||||||
this.inputLength = 20;
|
this.inputLength = 20;
|
||||||
}
|
}
|
||||||
if (this.filterable) this.$refs.input.focus();
|
if (this.filterable) this.$refs.input.focus();
|
||||||
|
} else {
|
||||||
|
this.$emit('input', option.value);
|
||||||
|
this.visible = false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -601,7 +600,9 @@
|
||||||
deleteTag(event, tag) {
|
deleteTag(event, tag) {
|
||||||
let index = this.selected.indexOf(tag);
|
let index = this.selected.indexOf(tag);
|
||||||
if (index > -1 && !this.disabled) {
|
if (index > -1 && !this.disabled) {
|
||||||
this.value.splice(index, 1);
|
const value = this.value.slice();
|
||||||
|
value.splice(index, 1);
|
||||||
|
this.$emit('input', value);
|
||||||
this.$emit('remove-tag', tag);
|
this.$emit('remove-tag', tag);
|
||||||
}
|
}
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
|
|
|
@ -429,6 +429,7 @@ describe('Select', () => {
|
||||||
vm.value = ['选项1'];
|
vm.value = ['选项1'];
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
options[1].click();
|
options[1].click();
|
||||||
|
setTimeout(() => {
|
||||||
options[3].click();
|
options[3].click();
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
expect(vm.value.indexOf('选项2') > -1 && vm.value.indexOf('选项4') > -1).to.true;
|
expect(vm.value.indexOf('选项2') > -1 && vm.value.indexOf('选项4') > -1).to.true;
|
||||||
|
@ -440,6 +441,7 @@ describe('Select', () => {
|
||||||
}, 100);
|
}, 100);
|
||||||
}, 100);
|
}, 100);
|
||||||
}, 100);
|
}, 100);
|
||||||
|
}, 100);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('multiple remove-tag', done => {
|
it('multiple remove-tag', done => {
|
||||||
|
|
Loading…
Reference in New Issue