diff --git a/packages/combo-box/src/vaadin-combo-box-mixin.js b/packages/combo-box/src/vaadin-combo-box-mixin.js index 9b871bf022..dcda823a80 100644 --- a/packages/combo-box/src/vaadin-combo-box-mixin.js +++ b/packages/combo-box/src/vaadin-combo-box-mixin.js @@ -930,6 +930,14 @@ export const ComboBoxMixin = (subclass) => this.opened || this.autoOpenDisabled ? this.$.dropdown.indexOfLabel(this.filter) : this._indexOfValue(this.value, this.filteredItems); + + // see https://github.com/vaadin/web-components/issues/2615 + if (this.selectedItem === null && this._focusedIndex >= 0) { + const filteredItem = this.filteredItems[this._focusedIndex]; + if (this._getItemValue(filteredItem) === this.value) { + this._selectItemForValue(this.value); + } + } } } diff --git a/packages/combo-box/test/filtering.test.js b/packages/combo-box/test/filtering.test.js index 43eee0531b..f763c9544f 100644 --- a/packages/combo-box/test/filtering.test.js +++ b/packages/combo-box/test/filtering.test.js @@ -390,3 +390,27 @@ describe('filtered items attribute', () => { expect(comboBox._focusedIndex).to.eql(1); }); }); + +describe('value attribute', () => { + let comboBox, input; + + beforeEach(() => { + comboBox = fixtureSync(``); + input = comboBox.inputElement; + }); + + it('should be able to be set before filtered items', () => { + comboBox.filteredItems = ['foo', 'bar', 'baz']; + expect(comboBox.selectedItem).to.eql('foo'); + expect(input.value).to.eql('foo'); + }); + + // see https://github.com/vaadin/web-components/issues/2615 + it('should not reset value after blur when set as html attribute', () => { + comboBox.filteredItems = ['foo']; + comboBox.value = ''; + comboBox.focus(); + comboBox.blur(); + expect(comboBox.value).to.equal(''); + }); +});