Skip to content

Commit

Permalink
fix: prevent scrolling to a placeholder on open
Browse files Browse the repository at this point in the history
  • Loading branch information
tomivirkki committed Sep 4, 2021
1 parent 33be450 commit f5c53c2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ class ComboBoxDropdownWrapperElement extends PolymerElement {
}

_setOverlayHeight() {
if (!this.opened || !this.positionTarget) {
if (!this.__virtualizer || !this.opened || !this.positionTarget) {
return;
}

Expand Down Expand Up @@ -374,7 +374,7 @@ class ComboBoxDropdownWrapperElement extends PolymerElement {
}

_scrollIntoView(index) {
if (!(this.opened && index >= 0)) {
if (!this.__virtualizer || !(this.opened && index >= 0)) {
return;
}
const visibleItemsCount = this._visibleItemsCount();
Expand Down
2 changes: 1 addition & 1 deletion packages/vaadin-combo-box/src/vaadin-combo-box-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,7 @@ export const ComboBoxMixin = (subclass) =>
_indexOfValue(value, items) {
if (items && this._isValidValue(value)) {
for (let i = 0; i < items.length; i++) {
if (this._getItemValue(items[i]) === value) {
if (items[i] !== this.__placeHolder && this._getItemValue(items[i]) === value) {
return i;
}
}
Expand Down
17 changes: 16 additions & 1 deletion packages/vaadin-combo-box/test/lazy-loading.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from '@esm-bundle/chai';
import sinon from 'sinon';
import { fixtureSync, nextFrame, enterKeyDown, fire } from '@vaadin/testing-helpers';
import { fixtureSync, nextFrame, aTimeout, enterKeyDown, fire } from '@vaadin/testing-helpers';
import { flush } from '@polymer/polymer/lib/utils/flush.js';
import '@polymer/iron-input/iron-input.js';
import { ComboBoxPlaceholder } from '../src/vaadin-combo-box-placeholder.js';
Expand Down Expand Up @@ -827,6 +827,21 @@ describe('lazy loading', () => {
comboBox.opened = true;
});

it('should be scrolled to start on reopen', async () => {
comboBox.dataProvider = spyAsyncDataProvider;
comboBox.size = SIZE;
comboBox.opened = false;

// Wait for the async data provider to respond
await aTimeout(0);

// Reopen
comboBox.open();
await nextFrame();

expect(getViewportItems(comboBox)[0].index).to.eql(0);
});

it('should replace filteredItems with placeholders', () => {
comboBox.dataProvider = spyAsyncDataProvider;
comboBox.size = SIZE;
Expand Down

0 comments on commit f5c53c2

Please sign in to comment.