Skip to content

Commit 9506724

Browse files
authored
fix: allow to set virtualizer items when not opened (#7325)
1 parent 2efeeeb commit 9506724

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

packages/combo-box/src/vaadin-combo-box-scroller-mixin.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,6 @@ export const ComboBoxScrollerMixin = (superClass) =>
148148
return;
149149
}
150150

151-
if (!this.__virtualizer) {
152-
this.__initVirtualizer();
153-
}
154-
155151
this.__virtualizer.update();
156152
}
157153

@@ -226,13 +222,8 @@ export const ComboBoxScrollerMixin = (superClass) =>
226222

227223
/** @private */
228224
__itemsChanged(items) {
229-
if (items && this.opened) {
230-
if (!this.__virtualizer) {
231-
this.__initVirtualizer();
232-
}
233-
234-
this.__virtualizer.size = items.length;
235-
this.__virtualizer.flush();
225+
if (items && this.__virtualizer) {
226+
this.__setVirtualizerItems(items);
236227
this.requestContentUpdate();
237228
}
238229
}
@@ -245,10 +236,24 @@ export const ComboBoxScrollerMixin = (superClass) =>
245236
/** @private */
246237
__openedChanged(opened) {
247238
if (opened) {
239+
if (!this.__virtualizer) {
240+
this.__initVirtualizer();
241+
242+
if (this.items) {
243+
this.__setVirtualizerItems(this.items);
244+
}
245+
}
246+
248247
this.requestContentUpdate();
249248
}
250249
}
251250

251+
/** @private */
252+
__setVirtualizerItems(items) {
253+
this.__virtualizer.size = items.length;
254+
this.__virtualizer.flush();
255+
}
256+
252257
/** @private */
253258
__selectedItemChanged() {
254259
this.requestContentUpdate();

packages/combo-box/test/lazy-loading.common.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,6 +1009,10 @@ describe('lazy loading', () => {
10091009
const pages = spyDataProvider.getCalls().map((call) => call.args[0].page);
10101010
expect(pages).to.contain(1);
10111011
});
1012+
1013+
it('should reset visible items count to 0', () => {
1014+
expect(getVisibleItemsCount(comboBox)).to.equal(0);
1015+
});
10121016
});
10131017

10141018
describe('using data provider, lost focus before data is returned', () => {

0 commit comments

Comments
 (0)