Select: fix default-first-option on created options

pull/8792/head
Leopoldthecoder 2017-12-12 18:56:11 +08:00 committed by 杨奕
parent b027f69e97
commit e64ba965d6
1 changed files with 12 additions and 2 deletions

View File

@ -691,16 +691,26 @@
checkDefaultFirstOption() {
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) {
const option = this.options[i];
if (this.query) {
// pick first options that passes the filter
// highlight first options that passes the filter
if (!option.disabled && !option.groupDisabled && option.visible) {
this.hoverIndex = i;
break;
}
} else {
// pick currently selected option
// highlight currently selected option
if (option.itemSelected) {
this.hoverIndex = i;
break;