mirror of https://github.com/ElemeFE/element
Select: fix default-first-option on created options
parent
b027f69e97
commit
e64ba965d6
|
@ -691,16 +691,26 @@
|
||||||
|
|
||||||
checkDefaultFirstOption() {
|
checkDefaultFirstOption() {
|
||||||
this.hoverIndex = -1;
|
this.hoverIndex = -1;
|
||||||
|
// highlight the created option
|
||||||
|
let hasCreated = false;
|
||||||
|
for (let i = this.options.length - 1; i >= 0; i--) {
|
||||||
|
if (this.options[i].created) {
|
||||||
|
hasCreated = true;
|
||||||
|
this.hoverIndex = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (hasCreated) return;
|
||||||
for (let i = 0; i !== this.options.length; ++i) {
|
for (let i = 0; i !== this.options.length; ++i) {
|
||||||
const option = this.options[i];
|
const option = this.options[i];
|
||||||
if (this.query) {
|
if (this.query) {
|
||||||
// pick first options that passes the filter
|
// highlight first options that passes the filter
|
||||||
if (!option.disabled && !option.groupDisabled && option.visible) {
|
if (!option.disabled && !option.groupDisabled && option.visible) {
|
||||||
this.hoverIndex = i;
|
this.hoverIndex = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// pick currently selected option
|
// highlight currently selected option
|
||||||
if (option.itemSelected) {
|
if (option.itemSelected) {
|
||||||
this.hoverIndex = i;
|
this.hoverIndex = i;
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue