From 405cfcf464bb41a3712719c185dd0c7a7342c310 Mon Sep 17 00:00:00 2001 From: web-padawan Date: Thu, 11 Apr 2024 16:54:10 +0300 Subject: [PATCH 1/2] fix: allow to set virtualizer items when not opened --- .../src/vaadin-combo-box-scroller-mixin.js | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/packages/combo-box/src/vaadin-combo-box-scroller-mixin.js b/packages/combo-box/src/vaadin-combo-box-scroller-mixin.js index 12690c4f2d..4fa3898219 100644 --- a/packages/combo-box/src/vaadin-combo-box-scroller-mixin.js +++ b/packages/combo-box/src/vaadin-combo-box-scroller-mixin.js @@ -148,10 +148,6 @@ export const ComboBoxScrollerMixin = (superClass) => return; } - if (!this.__virtualizer) { - this.__initVirtualizer(); - } - this.__virtualizer.update(); } @@ -226,13 +222,8 @@ export const ComboBoxScrollerMixin = (superClass) => /** @private */ __itemsChanged(items) { - if (items && this.opened) { - if (!this.__virtualizer) { - this.__initVirtualizer(); - } - - this.__virtualizer.size = items.length; - this.__virtualizer.flush(); + if (items && this.__virtualizer) { + this.__setVirtualizerItems(items); this.requestContentUpdate(); } } @@ -245,10 +236,24 @@ export const ComboBoxScrollerMixin = (superClass) => /** @private */ __openedChanged(opened) { if (opened) { + if (!this.__virtualizer) { + this.__initVirtualizer(); + + if (this.items) { + this.__setVirtualizerItems(this.items); + } + } + this.requestContentUpdate(); } } + /** @private */ + __setVirtualizerItems(items) { + this.__virtualizer.size = items.length; + this.__virtualizer.flush(); + } + /** @private */ __selectedItemChanged() { this.requestContentUpdate(); From c0e5d3d6e97d6ff9d2b9f9728969e360709374de Mon Sep 17 00:00:00 2001 From: web-padawan Date: Thu, 11 Apr 2024 17:27:11 +0300 Subject: [PATCH 2/2] test: add test to ensure items are updated when closed --- packages/combo-box/test/lazy-loading.common.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/combo-box/test/lazy-loading.common.js b/packages/combo-box/test/lazy-loading.common.js index 77f727d885..475fff8aa2 100644 --- a/packages/combo-box/test/lazy-loading.common.js +++ b/packages/combo-box/test/lazy-loading.common.js @@ -1009,6 +1009,10 @@ describe('lazy loading', () => { const pages = spyDataProvider.getCalls().map((call) => call.args[0].page); expect(pages).to.contain(1); }); + + it('should reset visible items count to 0', () => { + expect(getVisibleItemsCount(comboBox)).to.equal(0); + }); }); describe('using data provider, lost focus before data is returned', () => {