Skip to content

Commit 5e03e67

Browse files
authored
fix: clear on Esc if clear button is visible (#3804)
1 parent 0b08c6a commit 5e03e67

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

‎packages/multi-select-combo-box/src/vaadin-multi-select-combo-box.js‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,12 @@ class MultiSelectComboBox extends ResizeMixin(InputControlMixin(ThemableMixin(El
823823
*/
824824
_onKeyDown(event) {
825825
const items = this.selectedItems || [];
826+
827+
if (event.key === 'Escape' && this.clearButtonVisible && items.length) {
828+
this.selectedItems = [];
829+
return;
830+
}
831+
826832
if (!this.readonly && event.key === 'Backspace' && items.length && this.inputElement.value === '') {
827833
this.__removeItem(items[items.length - 1]);
828834
}

‎packages/multi-select-combo-box/test/basic.test.js‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,21 @@ describe('basic', () => {
243243
clearButton.click();
244244
expect(internal.opened).to.be.false;
245245
});
246+
247+
it('should clear selected items on Esc when clear button is visible', async () => {
248+
comboBox.selectedItems = ['apple', 'orange'];
249+
inputElement.focus();
250+
await sendKeys({ press: 'Escape' });
251+
expect(comboBox.selectedItems).to.deep.equal([]);
252+
});
253+
254+
it('should not clear selected items on Esc when clear button is not visible', async () => {
255+
comboBox.selectedItems = ['apple', 'orange'];
256+
comboBox.clearButtonVisible = false;
257+
inputElement.focus();
258+
await sendKeys({ press: 'Escape' });
259+
expect(comboBox.selectedItems).to.deep.equal(['apple', 'orange']);
260+
});
246261
});
247262

248263
describe('chips', () => {

0 commit comments

Comments
 (0)