Skip to content

Commit 01d7ac5

Browse files
authored
fix: update items on clear button click (#3307)
1 parent cb9c88f commit 01d7ac5

3 files changed

Lines changed: 30 additions & 7 deletions

File tree

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,8 @@ export const ComboBoxMixin = (subclass) =>
313313
return;
314314
}
315315

316+
this.$.dropdown._scroller.requestContentUpdate();
317+
316318
this._getItemElements().forEach((item) => {
317319
item.requestContentUpdate();
318320
});
@@ -414,6 +416,11 @@ export const ComboBoxMixin = (subclass) =>
414416
_handleClearButtonClick(event) {
415417
event.preventDefault();
416418
this._clear();
419+
420+
// De-select dropdown item
421+
if (this.opened) {
422+
this.requestContentUpdate();
423+
}
417424
}
418425

419426
/** @private */

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ export class ComboBoxScroller extends PolymerElement {
136136
}
137137

138138
__openedChanged(opened) {
139-
if (this.__virtualizer && opened) {
140-
this.__virtualizer.update();
139+
if (opened) {
140+
this.requestContentUpdate();
141141
}
142142
}
143143

@@ -163,6 +163,12 @@ export class ComboBoxScroller extends PolymerElement {
163163
});
164164
}
165165

166+
requestContentUpdate() {
167+
if (this.__virtualizer) {
168+
this.__virtualizer.update();
169+
}
170+
}
171+
166172
scrollIntoView(index) {
167173
if (!(this.opened && index >= 0)) {
168174
return;
@@ -232,29 +238,29 @@ export class ComboBoxScroller extends PolymerElement {
232238
this.__virtualizer.flush();
233239
// Ensure the total count of items is properly announced.
234240
this.setAttribute('aria-setsize', items.length);
235-
this.__virtualizer.update();
241+
this.requestContentUpdate();
236242
}
237243
}
238244

239245
/** @private */
240246
__loadingChanged(loading) {
241247
if (this.__virtualizer && !loading) {
242-
setTimeout(() => this.__virtualizer.update());
248+
setTimeout(() => this.requestContentUpdate());
243249
}
244250
}
245251

246252
/** @private */
247253
__focusedIndexChanged(index) {
248254
if (this.__virtualizer && index >= 0) {
249-
this.__virtualizer.update();
255+
this.requestContentUpdate();
250256
this.scrollIntoView(index);
251257
}
252258
}
253259

254260
/** @private */
255261
__rendererChanged(renderer, oldRenderer) {
256-
if (this.__virtualizer && (renderer || oldRenderer)) {
257-
this.__virtualizer.update();
262+
if (renderer || oldRenderer) {
263+
this.requestContentUpdate();
258264
}
259265
}
260266

‎packages/combo-box/test/selecting-items.test.js‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,16 @@ describe('clearing a selection', () => {
282282
expect(comboBox.opened).to.eql(true);
283283
});
284284

285+
it('should de-select dropdown item after clearing a selection', () => {
286+
comboBox.open();
287+
288+
const item = document.querySelector('vaadin-combo-box-item');
289+
expect(item.hasAttribute('selected')).to.be.true;
290+
291+
clearIcon.click();
292+
expect(item.hasAttribute('selected')).to.be.false;
293+
});
294+
285295
it('should not open the dropdown after clearing a selection', () => {
286296
clearIcon.click();
287297

0 commit comments

Comments
 (0)