diff --git a/packages/select/src/select.vue b/packages/select/src/select.vue index 01bf4879b..31882c2e9 100644 --- a/packages/select/src/select.vue +++ b/packages/select/src/select.vue @@ -191,7 +191,8 @@ default() { return t('el.select.placeholder'); } - } + }, + defaultFirstOption: Boolean }, data() { @@ -264,6 +265,25 @@ this.broadcast('ElOption', 'queryChange', val); this.broadcast('ElOptionGroup', 'queryChange'); } + if (this.defaultFirstOption && (this.filterable || this.remote) && this.filteredOptionsCount) { + this.hoverIndex = -1; + 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; + } + } + } + } }, visible(val) { diff --git a/test/unit/specs/select.spec.js b/test/unit/specs/select.spec.js index 1a7b2c3e6..1dc92be2c 100644 --- a/test/unit/specs/select.spec.js +++ b/test/unit/specs/select.spec.js @@ -404,6 +404,49 @@ describe('Select', () => { }, 10); }); + it('default-first-option', done => { + vm = createVue({ + template: ` +