Skip to content

Commit

Permalink
fix: allow to set virtualizer items when not opened (#7325)
Browse files Browse the repository at this point in the history
  • Loading branch information
web-padawan authored Apr 12, 2024
1 parent 2efeeeb commit 9506724
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
27 changes: 16 additions & 11 deletions packages/combo-box/src/vaadin-combo-box-scroller-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,6 @@ export const ComboBoxScrollerMixin = (superClass) =>
return;
}

if (!this.__virtualizer) {
this.__initVirtualizer();
}

this.__virtualizer.update();
}

Expand Down Expand Up @@ -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();
}
}
Expand All @@ -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();
Expand Down
4 changes: 4 additions & 0 deletions packages/combo-box/test/lazy-loading.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 9506724

Please sign in to comment.