Skip to content

Commit cdbe1a6

Browse files
committed
fix(aria/combobox): escape behavior
1 parent 671fdc7 commit cdbe1a6

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/aria/ui-patterns/combobox/combobox.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ export class ComboboxPattern<T extends ListItem<V>, V> {
152152
if (!this.expanded()) {
153153
return new KeyboardEventManager()
154154
.on('ArrowDown', () => this.open({first: true}))
155-
.on('ArrowUp', () => this.open({last: true}));
155+
.on('ArrowUp', () => this.open({last: true}))
156+
.on('Escape', () => this.close({reset: true}));
156157
}
157158

158159
const popupControls = this.inputs.popupControls();
@@ -366,20 +367,24 @@ export class ComboboxPattern<T extends ListItem<V>, V> {
366367

367368
const popupControls = this.inputs.popupControls();
368369

369-
if (this.inputs.filterMode() === 'highlight' && popupControls?.activeId()) {
370-
popupControls.unfocus();
371-
popupControls.clearSelection();
370+
if (!this.expanded()) {
371+
this.inputs.inputValue?.set('');
372+
popupControls?.clearSelection();
372373

373374
const inputEl = this.inputs.inputEl();
375+
374376
if (inputEl) {
375-
inputEl.value = this.inputs.inputValue!();
377+
inputEl.value = '';
376378
}
379+
} else if (this.expanded()) {
380+
this.close();
377381

378-
return;
379-
}
382+
const selectedItem = popupControls?.getSelectedItem();
380383

381-
this.close();
382-
this.inputs.popupControls()?.clearSelection();
384+
if (selectedItem?.searchTerm() !== this.inputs.inputValue!()) {
385+
popupControls?.clearSelection();
386+
}
387+
}
383388
}
384389

385390
/** Opens the combobox. */

0 commit comments

Comments
 (0)