Select: fix filterable init value issue, fixed #2196

pull/2236/head
Leopoldthecoder 2017-01-05 22:31:37 +08:00
parent 68c1c84875
commit 3b5248ec2a
2 changed files with 30 additions and 20 deletions

View File

@ -387,6 +387,7 @@
} }
this.selectedLabel = option.currentLabel; this.selectedLabel = option.currentLabel;
this.selected = option; this.selected = option;
if (this.filterable) this.query = this.selectedLabel;
return; return;
} }
let result = []; let result = [];

View File

@ -48,6 +48,7 @@ describe('Select', () => {
<el-option <el-option
v-for="item in options" v-for="item in options"
:label="item.label" :label="item.label"
:key="item.value"
:disabled="item.disabled" :disabled="item.disabled"
:value="item.value"> :value="item.value">
</el-option> </el-option>
@ -373,13 +374,15 @@ describe('Select', () => {
it('filterable', done => { it('filterable', done => {
vm = getSelectVm({ filterable: true }); vm = getSelectVm({ filterable: true });
const select = vm.$children[0]; const select = vm.$children[0];
select.selectedLabel = '面';
select.onInputChange();
select.visible = true;
setTimeout(() => { setTimeout(() => {
expect(select.filteredOptionsCount).to.equal(1); select.selectedLabel = '面';
done(); select.onInputChange();
}, 100); select.visible = true;
setTimeout(() => {
expect(select.filteredOptionsCount).to.equal(1);
done();
}, 10);
}, 10);
}); });
it('filterable with custom filter-method', done => { it('filterable with custom filter-method', done => {
@ -390,28 +393,34 @@ describe('Select', () => {
}; };
vm = getSelectVm({ filterable: true, filterMethod }); vm = getSelectVm({ filterable: true, filterMethod });
const select = vm.$children[0]; const select = vm.$children[0];
select.query = '面'; select.$el.querySelector('input').focus();
setTimeout(() => { setTimeout(() => {
expect(select.filteredOptionsCount).to.equal(4); select.selectedLabel = '面';
done(); select.onInputChange();
}, 100); setTimeout(() => {
expect(select.filteredOptionsCount).to.equal(4);
done();
}, 10);
}, 10);
}); });
it('allow create', done => { it('allow create', done => {
vm = getSelectVm({ filterable: true, allowCreate: true }); vm = getSelectVm({ filterable: true, allowCreate: true });
const select = vm.$children[0]; const select = vm.$children[0];
select.selectedLabel = 'new'; select.$el.querySelector('input').focus();
select.onInputChange();
select.visible = true;
setTimeout(() => { setTimeout(() => {
const options = document.querySelectorAll('.el-select-dropdown__item span'); select.selectedLabel = 'new';
const target = [].filter.call(options, option => option.innerText === 'new'); select.onInputChange();
target[0].click();
setTimeout(() => { setTimeout(() => {
expect(select.value.indexOf('new') > -1).to.true; const options = document.querySelectorAll('.el-select-dropdown__item span');
done(); const target = [].filter.call(options, option => option.innerText === 'new');
}, 50); target[0].click();
}, 50); setTimeout(() => {
expect(select.value.indexOf('new') > -1).to.true;
done();
}, 10);
}, 10);
}, 10);
}); });
it('multiple select', done => { it('multiple select', done => {