From 2e1936cec8047528c586c8e0ac98f9092c7df860 Mon Sep 17 00:00:00 2001 From: dawn <90008@gaze.systems> Date: Thu, 21 May 2026 11:29:29 +0300 Subject: [PATCH] make search bar actually focusable with / --- src/layout.tsx | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/layout.tsx b/src/layout.tsx index 1cccc94..414b8cc 100644 --- a/src/layout.tsx +++ b/src/layout.tsx @@ -247,6 +247,22 @@ const TopbarSearch: Component = () => { const location = useLocation(); const [query, setQuery] = createSignal(''); + let inputRef: HTMLInputElement | undefined; + onMount(() => { + const handler = (e: KeyboardEvent) => { + if (e.ctrlKey || e.metaKey) return; + if (e.key === "/") { + e.preventDefault(); + inputRef?.focus(); + } else if (e.key === "Escape") { + setQuery(''); + inputRef?.blur(); + } + } + window.addEventListener("keydown", handler) + onCleanup(() => window.removeEventListener("keydown", handler)) + }); + createEffect(() => { if (location.pathname !== '/search') { setQuery(''); @@ -268,6 +284,7 @@ const TopbarSearch: Component = () => {