From a569ff8e105aff08c29235f8ab37d311b1f7f099 Mon Sep 17 00:00:00 2001 From: "Tom (plebeius.eth)" Date: Fri, 31 Jan 2025 12:33:52 +0100 Subject: [PATCH] Update topbar.tsx --- src/components/topbar/topbar.tsx | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/components/topbar/topbar.tsx b/src/components/topbar/topbar.tsx index 2392afe6..86bd5fd7 100644 --- a/src/components/topbar/topbar.tsx +++ b/src/components/topbar/topbar.tsx @@ -35,6 +35,19 @@ const SearchBar = ({ setShowSearchBar }: { setShowSearchBar: (show: boolean) => }; }, [handleClickOutside]); + useEffect(() => { + const handleEscapeKey = (event: KeyboardEvent) => { + if (event.key === 'Escape') { + setShowSearchBar(false); + } + }; + + document.addEventListener('keydown', handleEscapeKey); + return () => { + document.removeEventListener('keydown', handleEscapeKey); + }; + }, [setShowSearchBar]); + const handleSearchSubmit = (event: React.FormEvent) => { event.preventDefault(); const searchInput = searchInputRef.current?.value;