Skip to content

Commit b9f590b

Browse files
authored
fix: update virtualizer size on requestContentUpdate (#7374)
1 parent d7eeba2 commit b9f590b

File tree

2 files changed

+31
-14
lines changed

2 files changed

+31
-14
lines changed

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

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,20 @@ export const ComboBoxScrollerMixin = (superClass) =>
141141
}
142142

143143
/**
144-
* Requests an update for the virtualizer to re-render items.
144+
* Updates the virtualizer's size and items.
145145
*/
146146
requestContentUpdate() {
147-
if (!this.opened) {
147+
if (!this.__virtualizer) {
148148
return;
149149
}
150150

151-
this.__virtualizer.update();
151+
if (this.items) {
152+
this.__virtualizer.size = this.items.length;
153+
}
154+
155+
if (this.opened) {
156+
this.__virtualizer.update();
157+
}
152158
}
153159

154160
/**
@@ -223,7 +229,6 @@ export const ComboBoxScrollerMixin = (superClass) =>
223229
/** @private */
224230
__itemsChanged(items) {
225231
if (items && this.__virtualizer) {
226-
this.__setVirtualizerItems(items);
227232
this.requestContentUpdate();
228233
}
229234
}
@@ -238,21 +243,12 @@ export const ComboBoxScrollerMixin = (superClass) =>
238243
if (opened) {
239244
if (!this.__virtualizer) {
240245
this.__initVirtualizer();
241-
242-
if (this.items) {
243-
this.__setVirtualizerItems(this.items);
244-
}
245246
}
246247

247248
this.requestContentUpdate();
248249
}
249250
}
250251

251-
/** @private */
252-
__setVirtualizerItems(items) {
253-
this.__virtualizer.size = items.length;
254-
}
255-
256252
/** @private */
257253
__selectedItemChanged() {
258254
this.requestContentUpdate();

packages/combo-box/test/external-filtering.common.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { expect } from '@esm-bundle/chai';
22
import { aTimeout, enter, fixtureSync, nextRender } from '@vaadin/testing-helpers';
3-
import { getFocusedItemIndex, setInputValue } from './helpers.js';
3+
import { getAllItems, getFocusedItemIndex, setInputValue } from './helpers.js';
44

55
describe('external filtering', () => {
66
let comboBox, overlay;
@@ -84,6 +84,27 @@ describe('external filtering', () => {
8484
});
8585
});
8686

87+
describe('requestContentUpdate', () => {
88+
beforeEach(async () => {
89+
comboBox = fixtureSync('<vaadin-combo-box></vaadin-combo-box>');
90+
comboBox.filteredItems = ['Item 0'];
91+
await nextRender();
92+
comboBox.opened = true;
93+
});
94+
95+
it('should re-render items after modifying existing filteredItems through mutation', () => {
96+
comboBox.filteredItems[0] = 'New Item';
97+
comboBox.requestContentUpdate();
98+
expect(getAllItems(comboBox).map((item) => item.textContent)).to.eql(['New Item']);
99+
});
100+
101+
it('should re-render items after adding more filteredItems through mutation', () => {
102+
comboBox.filteredItems.push('Item 1');
103+
comboBox.requestContentUpdate();
104+
expect(getAllItems(comboBox).map((item) => item.textContent)).to.eql(['Item 0', 'Item 1']);
105+
});
106+
});
107+
87108
describe('filtered items attribute', () => {
88109
beforeEach(async () => {
89110
comboBox = fixtureSync(`<vaadin-combo-box filtered-items='["a", "b", "c"]' value='b'></vaadin-combo-box>`);

0 commit comments

Comments
 (0)