Skip to content

Commit

Permalink
fix: avoid clearing filter when pressing clear button on mobile (#7091)…
Browse files Browse the repository at this point in the history
… (#7092)

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.

Co-authored-by: Sascha Ißbrücker <sissbruecker@vaadin.com>
  • Loading branch information
vaadin-bot and sissbruecker authored Jan 18, 2024
1 parent 4aee4f4 commit 50b6f0e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,9 @@ class MultiSelectComboBox extends ResizeMixin(InputControlMixin(ThemableMixin(El
_onClearButtonTouchend(event) {
// Cancel the following click and focus events
event.preventDefault();
// Prevent default combo box behavior which can otherwise unnecessarily
// clear the input and filter
event.stopPropagation();

this.clear();
}
Expand Down
11 changes: 11 additions & 0 deletions packages/multi-select-combo-box/test/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,17 @@ describe('basic', () => {
clearButton.dispatchEvent(new CustomEvent('touchend', { cancelable: true }));
expect(comboBox.selectedItems).to.deep.equal([]);
});

it('should not clear filter on clear button touchend', async () => {
comboBox.selectedItems = ['apple', 'orange'];
inputElement.focus();
await sendKeys({ type: 'app' });

clearButton.dispatchEvent(new CustomEvent('touchend', { cancelable: true, bubbles: true }));
expect(inputElement.value).to.equal('app');
expect(comboBox.filter).to.equal('app');
expect(comboBox.filteredItems).to.deep.equal(['apple']);
});
});

describe('toggle button', () => {
Expand Down

0 comments on commit 50b6f0e

Please sign in to comment.