Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: postpone virtualizer creation until overlay is opened (#7277) (CP: 24.3) #7321

Merged
merged 2 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions integration/tests/component-relayout-page.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { expect } from '@esm-bundle/chai';
import { fixtureSync, nextRender } from '@vaadin/testing-helpers';
import { ComboBox } from '@vaadin/combo-box';
import { ContextMenu } from '@vaadin/context-menu';
import { MenuBar } from '@vaadin/menu-bar';

[
{ tagName: ComboBox.is },
{ tagName: ContextMenu.is },
{
tagName: MenuBar.is,
Expand Down
44 changes: 31 additions & 13 deletions packages/combo-box/src/vaadin-combo-box-scroller-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,23 +132,17 @@ export const ComboBoxScrollerMixin = (superClass) =>
this.addEventListener('click', (e) => e.stopPropagation());

this.__patchWheelOverScrolling();

this.__virtualizer = new Virtualizer({
createElements: this.__createElements.bind(this),
updateElement: this._updateElement.bind(this),
elementsContainer: this,
scrollTarget: this,
scrollContainer: this.$.selector,
});
}

/**
* Requests an update for the virtualizer to re-render items.
*/
requestContentUpdate() {
if (this.__virtualizer) {
this.__virtualizer.update();
if (!this.opened) {
return;
}

this.__virtualizer.update();
}

/**
Expand Down Expand Up @@ -208,11 +202,21 @@ export const ComboBoxScrollerMixin = (superClass) =>
return item === selectedItem;
}

/** @private */
__initVirtualizer() {
this.__virtualizer = new Virtualizer({
createElements: this.__createElements.bind(this),
updateElement: this._updateElement.bind(this),
elementsContainer: this,
scrollTarget: this,
scrollContainer: this.$.selector,
});
}

/** @private */
__itemsChanged(items) {
if (this.__virtualizer && items) {
this.__virtualizer.size = items.length;
this.__virtualizer.flush();
if (items && this.__virtualizer) {
this.__setVirtualizerItems(items);
this.requestContentUpdate();
}
}
Expand All @@ -225,10 +229,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.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,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
Loading