From 7d94e29dcb219e67ac043d687a101d65ad9fd1d5 Mon Sep 17 00:00:00 2001 From: JSC Date: Sat, 4 Oct 2025 14:41:59 +0200 Subject: [PATCH] feat: add global escape key handling to close search modal --- src/components/GlobalSearch.tsx | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/components/GlobalSearch.tsx b/src/components/GlobalSearch.tsx index c6f914c..cf9a112 100644 --- a/src/components/GlobalSearch.tsx +++ b/src/components/GlobalSearch.tsx @@ -159,6 +159,20 @@ export function GlobalSearch({ isOpen, onClose }: GlobalSearchProps) { } } + // Handle global escape key + useEffect(() => { + if (!isOpen) return + + const handleGlobalKeyDown = (e: KeyboardEvent) => { + if (e.key === 'Escape') { + onClose() + } + } + + window.addEventListener('keydown', handleGlobalKeyDown) + return () => window.removeEventListener('keydown', handleGlobalKeyDown) + }, [isOpen, onClose]) + if (!isOpen) return null return ( @@ -193,8 +207,8 @@ export function GlobalSearch({ isOpen, onClose }: GlobalSearchProps) { {/* Results */} - -
+ +
{loading && (
Searching...