fix: improve ComboBox tab key handling

This commit is contained in:
Brian West 2025-03-14 11:39:30 -05:00 committed by Eric Liu
commit f21aa222fb

View file

@ -175,7 +175,6 @@
filteredItems = []; filteredItems = [];
if (!selectedItem) { if (!selectedItem) {
selectedId = undefined; selectedId = undefined;
value = "";
highlightedIndex = -1; highlightedIndex = -1;
highlightedId = undefined; highlightedId = undefined;
} else { } else {
@ -283,7 +282,13 @@
open = true; open = true;
} }
}} }}
on:keydown on:keydown={(e) => {
// If there's a selection and user types a printable character, clear selection immediately
if (e.key.length === 1 && selectedItem) {
selectedId = undefined;
selectedItem = undefined;
}
}}
on:keydown|stopPropagation={(e) => { on:keydown|stopPropagation={(e) => {
const { key } = e; const { key } = e;
if (["Enter", "ArrowDown", "ArrowUp"].includes(key)) { if (["Enter", "ArrowDown", "ArrowUp"].includes(key)) {