Skip to content

Commit 89bace1

Browse files
authored
fix: avoid clearing filter when pressing clear button on mobile (#7091)
Disables the clear button logic from `vaadin-combo-box-mixin`, which clears the filter input when pressing the clear button. Instead, only the MSCB clear button logic is executed, which only clears the selection.
1 parent e042c3e commit 89bace1

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,6 +1067,9 @@ class MultiSelectComboBox extends ResizeMixin(InputControlMixin(ThemableMixin(El
10671067
_onClearButtonTouchend(event) {
10681068
// Cancel the following click and focus events
10691069
event.preventDefault();
1070+
// Prevent default combo box behavior which can otherwise unnecessarily
1071+
// clear the input and filter
1072+
event.stopPropagation();
10701073

10711074
this.clear();
10721075
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,17 @@ describe('basic', () => {
224224
clearButton.dispatchEvent(new CustomEvent('touchend', { cancelable: true }));
225225
expect(comboBox.selectedItems).to.deep.equal([]);
226226
});
227+
228+
it('should not clear filter on clear button touchend', async () => {
229+
comboBox.selectedItems = ['apple', 'orange'];
230+
inputElement.focus();
231+
await sendKeys({ type: 'app' });
232+
233+
clearButton.dispatchEvent(new CustomEvent('touchend', { cancelable: true, bubbles: true }));
234+
expect(inputElement.value).to.equal('app');
235+
expect(comboBox.filter).to.equal('app');
236+
expect(comboBox.filteredItems).to.deep.equal(['apple']);
237+
});
227238
});
228239

229240
describe('toggle button', () => {

0 commit comments

Comments
 (0)