mirror of https://github.com/ElemeFE/element
Select: fix default-first-option with remote
make default-first-option work with async filter/remote method test is updated to reflect this changepull/5127/head
parent
3206c02b40
commit
bd2e172fa3
|
@ -266,23 +266,7 @@
|
||||||
this.broadcast('ElOptionGroup', 'queryChange');
|
this.broadcast('ElOptionGroup', 'queryChange');
|
||||||
}
|
}
|
||||||
if (this.defaultFirstOption && (this.filterable || this.remote) && this.filteredOptionsCount) {
|
if (this.defaultFirstOption && (this.filterable || this.remote) && this.filteredOptionsCount) {
|
||||||
this.hoverIndex = -1;
|
this.checkDefaultFirstOption();
|
||||||
for (let i = 0; i !== this.options.length; ++i) {
|
|
||||||
const option = this.options[i];
|
|
||||||
if (val) {
|
|
||||||
// pick first options that passes the filter
|
|
||||||
if (!option.disabled && !option.groupDisabled && option.visible) {
|
|
||||||
this.hoverIndex = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// pick currently selected option
|
|
||||||
if (option.itemSelected) {
|
|
||||||
this.hoverIndex = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -346,6 +330,9 @@
|
||||||
if ([].indexOf.call(inputs, document.activeElement) === -1) {
|
if ([].indexOf.call(inputs, document.activeElement) === -1) {
|
||||||
this.setSelected();
|
this.setSelected();
|
||||||
}
|
}
|
||||||
|
if (this.defaultFirstOption && (this.filterable || this.remote) && this.filteredOptionsCount) {
|
||||||
|
this.checkDefaultFirstOption();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -651,6 +638,26 @@
|
||||||
handleResize() {
|
handleResize() {
|
||||||
this.resetInputWidth();
|
this.resetInputWidth();
|
||||||
if (this.multiple) this.resetInputHeight();
|
if (this.multiple) this.resetInputHeight();
|
||||||
|
},
|
||||||
|
|
||||||
|
checkDefaultFirstOption() {
|
||||||
|
this.hoverIndex = -1;
|
||||||
|
for (let i = 0; i !== this.options.length; ++i) {
|
||||||
|
const option = this.options[i];
|
||||||
|
if (this.query) {
|
||||||
|
// pick first options that passes the filter
|
||||||
|
if (!option.disabled && !option.groupDisabled && option.visible) {
|
||||||
|
this.hoverIndex = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// pick currently selected option
|
||||||
|
if (option.itemSelected) {
|
||||||
|
this.hoverIndex = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -426,6 +426,14 @@ describe('Select', () => {
|
||||||
options: ['1', '2', '3', '4', '5'],
|
options: ['1', '2', '3', '4', '5'],
|
||||||
value: ''
|
value: ''
|
||||||
};
|
};
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
filterMethod(query) {
|
||||||
|
// simulate async filterMethod / remoteMethod
|
||||||
|
setTimeout(() => {
|
||||||
|
this.options.filter(option => option.label.indexOf(query) !== -1);
|
||||||
|
}, 5);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, true);
|
}, true);
|
||||||
|
|
||||||
|
@ -443,7 +451,7 @@ describe('Select', () => {
|
||||||
expect(select.value).to.equal('3');
|
expect(select.value).to.equal('3');
|
||||||
done();
|
done();
|
||||||
}, 10);
|
}, 10);
|
||||||
}, 10);
|
}, 10); // wait for async filterMethod
|
||||||
}, 10);
|
}, 10);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue