diff --git a/src/vaadin-combo-box-dropdown-wrapper.html b/src/vaadin-combo-box-dropdown-wrapper.html index cd0ad48c6..9d6a08993 100644 --- a/src/vaadin-combo-box-dropdown-wrapper.html +++ b/src/vaadin-combo-box-dropdown-wrapper.html @@ -350,6 +350,9 @@ } _scrollIntoView(index) { + if (!(this.opened && index >= 0)) { + return; + } const visibleItemsCount = this._visibleItemsCount(); if (visibleItemsCount === undefined) { // Scroller is not visible. Moving is unnecessary. @@ -360,6 +363,9 @@ if (index > this._selector.lastVisibleIndex - 1) { // Index is below the bottom, scrolling down. Make the item appear at the bottom. + // First scroll to target (will be at the top of the scroller) to make sure it's rendered. + this._selector.scrollToIndex(index); + // Then calculate the index for the following scroll (to get the target to bottom of the scroller). targetIndex = index - visibleItemsCount + 1; } else if (index > this._selector.firstVisibleIndex) { // The item is already visible, scrolling is unnecessary per se. But we need to trigger iron-list to set diff --git a/test/filtering.html b/test/filtering.html index 334ea1468..89d8bfd39 100644 --- a/test/filtering.html +++ b/test/filtering.html @@ -385,15 +385,11 @@ comboBox = fixture('combobox'); }); - it('should properly display all items in the selector', done => { - comboBox.opened = true; - setTimeout(() => { - comboBox.filteredItems = Array.apply(null, Array(20)).map((_, i) => `item${i}`); - setTimeout(() => { - expect(comboBox.$.overlay._selector.querySelectorAll('vaadin-combo-box-item').length).to.equal(20); - done(); - }, 1); - }); + it('should properly display all items in the selector', () => { + comboBox.open(); + comboBox.filteredItems = Array.apply(null, Array(20)).map((_, i) => `item${i}`); + Polymer.flush(); + expect(comboBox.$.overlay._selector.querySelectorAll('vaadin-combo-box-item').length).to.equal(20); }); }); }); diff --git a/test/index.html b/test/index.html index 6c1569f89..72d0a021b 100644 --- a/test/index.html +++ b/test/index.html @@ -9,7 +9,7 @@ - + diff --git a/test/keyboard.html b/test/keyboard.html index 083340b89..860706d25 100644 --- a/test/keyboard.html +++ b/test/keyboard.html @@ -462,6 +462,7 @@ }); it('should scroll down after reaching the last visible item', () => { + selector.scrollToIndex(0); comboBox._focusedIndex = comboBox.$.overlay._visibleItemsCount() - 1; expect(selector.firstVisibleIndex).to.eql(0);