From e64ba965d695660ac2c55787e4311815ca4c3141 Mon Sep 17 00:00:00 2001 From: Leopoldthecoder Date: Tue, 12 Dec 2017 18:56:11 +0800 Subject: [PATCH] Select: fix default-first-option on created options --- packages/select/src/select.vue | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/select/src/select.vue b/packages/select/src/select.vue index b9427896a..7669bfa3b 100644 --- a/packages/select/src/select.vue +++ b/packages/select/src/select.vue @@ -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;