@vaadin/vaadin-combo-box
Advanced tools
Comparing version 5.4.0 to 5.4.1
@@ -13,3 +13,3 @@ { | ||
"name": "@vaadin/vaadin-combo-box", | ||
"version": "5.4.0", | ||
"version": "5.4.1", | ||
"main": "vaadin-combo-box.js", | ||
@@ -29,2 +29,4 @@ "author": "Vaadin Ltd", | ||
"resolutions": { | ||
"es-abstract": "1.17.6", | ||
"@types/doctrine": "0.0.3", | ||
"inherits": "2.0.3", | ||
@@ -31,0 +33,0 @@ "samsam": "1.1.3", |
@@ -104,2 +104,22 @@ /** | ||
/** | ||
* Used to recognize scroller reset after new items have been set | ||
* to iron-list and to ignore unwanted pages load. If 'true', then | ||
* skip loading of the pages until it becomes 'false'. | ||
*/ | ||
resetScrolling: { | ||
type: Boolean, | ||
value: false | ||
}, | ||
/** | ||
* Used to recognize if the filter changed, so to skip the | ||
* scrolling restore. If true, then scroll to 0 position. Restore | ||
* the previous position otherwise. | ||
*/ | ||
filterChanged: { | ||
type: Boolean, | ||
value: false | ||
}, | ||
_selectedItem: { | ||
@@ -136,3 +156,12 @@ type: 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 | ||
} | ||
}; | ||
@@ -142,3 +171,5 @@ } | ||
static get observers() { | ||
return ['_selectorChanged(_selector)', '_loadingChanged(loading)', '_openedChanged(opened, _items, loading)']; | ||
return ['_selectorChanged(_selector)', '_loadingChanged(loading)', | ||
'_openedChanged(opened, _items, loading)', | ||
'_restoreScrollerPosition(_items)']; | ||
} | ||
@@ -153,5 +184,42 @@ | ||
_getItems(opened, items) { | ||
return opened ? items : []; | ||
if (opened) { | ||
if (this._isNotEmpty(items) && this._selector && !this.filterChanged) { | ||
// iron-list triggers the scroller's reset after items update, and | ||
// this is not 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. | ||
const currentScrollerPosition = this._selector.firstVisibleIndex; | ||
if (currentScrollerPosition !== 0) { | ||
this._oldScrollerPosition = currentScrollerPosition; | ||
this.resetScrolling = true; | ||
} | ||
} | ||
// Let the position to be restored in the future calls unless it's not | ||
// caused by filtering | ||
this.filterChanged = false; | ||
return items; | ||
} | ||
return []; | ||
} | ||
_restoreScrollerPosition(items) { | ||
if (this._isNotEmpty(items) && this._selector && this._oldScrollerPosition !== 0) { | ||
// new items size might be less than old scrolling position | ||
this._selector.scrollToIndex(Math.min(items.length - 1, this._oldScrollerPosition)); | ||
this.resetScrolling = false; | ||
// reset position to 0 again in order to properly handle the filter | ||
// cases (scroll to 0 after typing the filter) | ||
this._oldScrollerPosition = 0; | ||
} | ||
} | ||
_isNotEmpty(items) { | ||
return !this._isEmpty(items); | ||
} | ||
_isEmpty(items) { | ||
return !items || !items.length; | ||
} | ||
_openedChanged(opened, items, loading) { | ||
@@ -167,3 +235,4 @@ if (this.$.dropdown.hasAttribute('disable-upgrade')) { | ||
// Do not dettach if opened but user types an invalid search | ||
this.$.dropdown.opened = !!(opened && (loading || this.$.dropdown.opened || items && items.length)); | ||
this.$.dropdown.opened = !!(opened && (loading || | ||
this.$.dropdown.opened || this._isNotEmpty(items))); | ||
} | ||
@@ -296,3 +365,4 @@ | ||
__requestItemByIndex(item, index) { | ||
if ((item instanceof ComboBoxPlaceholder) && index !== undefined) { | ||
if ((item instanceof ComboBoxPlaceholder) && index !== | ||
undefined && !this.resetScrolling) { | ||
this.dispatchEvent(new CustomEvent('index-requested', {detail: {index}})); | ||
@@ -457,3 +527,3 @@ } | ||
_hidden(itemsChange) { | ||
return !this.loading && (!this._items || !this._items.length); | ||
return !this.loading && (this._isEmpty(this._items)); | ||
} | ||
@@ -460,0 +530,0 @@ } |
@@ -758,2 +758,7 @@ /** | ||
} | ||
// Notify the dropdown about filter changing, so to let it skip the | ||
// scrolling restore | ||
this.$.overlay.filterChanged = true; | ||
if (this.items) { | ||
@@ -760,0 +765,0 @@ this.filteredItems = this._filterItems(this.items, filter); |
@@ -232,3 +232,3 @@ /** | ||
static get version() { | ||
return '5.4.0'; | ||
return '5.4.1'; | ||
} | ||
@@ -235,0 +235,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
142326
3631