Skip to content

SearXNG is a free internet metasearch engine which aggregates results from various search services and databases. Users are neither tracked nor profiled.

[feat] client/simple: show/hide autocomplete list on focus/blur

Aadniz5ab3ef774b5a
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<vo
const form = document.querySelector<HTMLFormElement>("#search");
form?.submit();
-
- autocomplete.classList.remove("open");
});
fragment.append(li);
@@ -80,6 +78,11 @@ listen("input", qInput, () => {
const autocomplete: HTMLElement | null = document.querySelector<HTMLElement>(".autocomplete");
const autocompleteList: HTMLUListElement | null = document.querySelector<HTMLUListElement>(".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");
+ });
}