diff --git a/client/simple/src/js/main/autocomplete.ts b/client/simple/src/js/main/autocomplete.ts index 7da197ddf..aea67c75d 100644 --- a/client/simple/src/js/main/autocomplete.ts +++ b/client/simple/src/js/main/autocomplete.ts @@ -44,8 +44,6 @@ const fetchResults = async (qInput: HTMLInputElement, query: string): Promise("#search"); form?.submit(); - - autocomplete.classList.remove("open"); }); fragment.append(li); @@ -80,6 +78,11 @@ listen("input", qInput, () => { const autocomplete: HTMLElement | null = document.querySelector(".autocomplete"); const autocompleteList: HTMLUListElement | null = document.querySelector(".autocomplete ul"); if (autocompleteList) { + listen("keydown", qInput, (event: KeyboardEvent) => { + if (event.key === "Escape") { + autocomplete?.classList.remove("open"); + } + }); listen("keyup", qInput, (event: KeyboardEvent) => { const listItems = [...autocompleteList.children] as HTMLElement[]; @@ -105,7 +108,6 @@ if (autocompleteList) { newCurrentIndex = (currentIndex + 1) % listItems.length; break; } - case "Tab": case "Enter": if (autocomplete) { autocomplete.classList.remove("open"); @@ -129,4 +131,12 @@ if (autocompleteList) { } } }); + + listen("blur", qInput, () => { + autocomplete?.classList.remove("open"); + }); + + listen("focus", qInput, () => { + autocomplete?.classList.add("open"); + }); }