Skip to content

Commit

Permalink
Merge ed6e863 into 225d182
Browse files Browse the repository at this point in the history
  • Loading branch information
mshabarov committed Sep 16, 2020
2 parents 225d182 + ed6e863 commit 520ba99
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 3 deletions.
15 changes: 15 additions & 0 deletions src/vaadin-combo-box-data-provider-mixin.html
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,21 @@
return true;
}

// Max item count in active range (items cache).
// This local var reflects the 'MAX_RANGE_COUNT' in combo box
// connector.
const MAX_RANGE_COUNT = Math.max(this.pageSize * 2, 500);

// We skip the page loading when the scrolling has been reset to 0
// position after assigning a new items to iron-list, because otherwise
// the connector's 'clearPageCallbacks' would be broken and the gaps in
// items list occur. Checking items cache size here, since the gaps only
// appear when the cache is fully populated and it should be possible for
// sure to load the page at the very beginning
if (this.$.overlay.resetScrolling && this.filteredItems.length > MAX_RANGE_COUNT) {
return false;
}

const loadedItem = this.filteredItems[page * this.pageSize];
if (loadedItem !== undefined) {
return loadedItem instanceof Vaadin.ComboBoxPlaceholder;
Expand Down
51 changes: 48 additions & 3 deletions src/vaadin-combo-box-dropdown-wrapper.html
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,15 @@
*/
theme: String,

/**
* Used to recognize scroller reset after new items have been set
* to iron-list and to ignore unwanted pages load
*/
resetScrolling: {
type: Boolean,
value: false
},

_selectedItem: {
type: Object
},
Expand Down Expand Up @@ -153,12 +162,23 @@

_selector: Object,

_itemIdPath: String
_itemIdPath: String,

/**
* Stores the scroller position before updating the 'items', in
* order to restore it immediately after 'items' have been updated
*/
_oldScrollerPosition: {
type: Number,
value: 0
}
};
}

static get observers() {
return ['_selectorChanged(_selector)', '_loadingChanged(loading)', '_openedChanged(opened, _items, loading)'];
return ['_selectorChanged(_selector)', '_loadingChanged(loading)',
'_openedChanged(opened, _items, loading)',
'_restoreScrollerPosition(_items)'];
}

_fireTouchAction(sourceEvent) {
Expand All @@ -168,7 +188,32 @@
}

_getItems(opened, items) {
return opened ? items : [];
if (opened) {
if (this._notEmpty(items)) {
// iron-list triggers the scroller reset after items update, and
// this is no appropriate for undefined size lazy loading.
// see https://github.com/vaadin/vaadin-combo-box-flow/issues/386
// We store iron-list scrolling position in order to restore
// it later on after the items have been updated.
this._oldScrollerPosition = this._selector.firstVisibleIndex;
this.resetScrolling = true;
}
return items;
}
return [];
}

_restoreScrollerPosition(items) {
if (this._notEmpty(items)) {
// new items size might be less than old scrolling position
this._selector.scrollToIndex(Math.min(items.length - 1, this._oldScrollerPosition));
this.resetScrolling = false;
}
}

_notEmpty(items) {
return this._selector !== undefined && items !== undefined &&
items.length > 0;
}

_openedChanged(opened, items, loading) {
Expand Down

0 comments on commit 520ba99

Please sign in to comment.