Skip to content

Commit

Permalink
set selectedItem after DOM attaching and before items set (Fixes #580)
Browse files Browse the repository at this point in the history
  • Loading branch information
asashour authored and vicsstar committed Jan 10, 2018
1 parent 957dd4e commit cfa1011
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/vaadin-combo-box-mixin.html
Original file line number Diff line number Diff line change
Expand Up @@ -583,17 +583,15 @@
}

_selectedItemChanged(selectedItem) {
if (!this.filteredItems) {
return;
}

if (selectedItem === null || selectedItem === undefined) {
if (!this.allowCustomValue) {
this.value = '';
}
if (this.filteredItems) {
if (!this.allowCustomValue) {
this.value = '';
}

this._updateHasValue(this.value !== '');
this._inputElementValue = this.value;
this._setHasValue(this.value !== '');
this._inputElementValue = this.value;
}
} else {
const value = this._getItemValue(selectedItem);
if (this.value !== value) {
Expand All @@ -610,7 +608,9 @@
}

this.$.overlay._selectedItem = selectedItem;
this._focusedIndex = this.filteredItems.indexOf(selectedItem);
if (this.filteredItems) {
this._focusedIndex = this.filteredItems.indexOf(selectedItem);
}
}

_valueChanged(value, oldVal) {
Expand Down
8 changes: 8 additions & 0 deletions test/selecting-items.html
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,14 @@
expect(newComboBox.value).to.equal('foo');
});

it('should be possible to set selectedItem after attaching to the DOM and before setting items', () => {
var newComboBox = combobox.cloneNode(true);
combobox.parentElement.appendChild(newComboBox);
newComboBox.selectedItem = 'foo';
newComboBox.items = ['foo', 'bar'];
expect(newComboBox.value).to.equal('foo');
});

describe('`change` event', () => {
it('should fire `value-changed` and `selected-item-changed` before `changed`', done => {
combobox.addEventListener('change', () => {
Expand Down

0 comments on commit cfa1011

Please sign in to comment.