From fba330b5d955919fa407ad7055bbbb2edf471413 Mon Sep 17 00:00:00 2001 From: Eric Allam Date: Fri, 1 Apr 2022 11:10:35 +0100 Subject: [PATCH] hitting esc when search input is focused and empty should close the search --- app/components/SearchPalette.tsx | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/components/SearchPalette.tsx b/app/components/SearchPalette.tsx index 8b00f19..6cd4e44 100644 --- a/app/components/SearchPalette.tsx +++ b/app/components/SearchPalette.tsx @@ -93,6 +93,16 @@ export function SearchPalette({ inputValue ? searchApi.search(inputValue) : searchApi.reset(), }); + const handleInputKeyDown = useCallback( + (e: React.KeyboardEvent) => { + if (e.key === "Escape" && onClose && cb.inputValue.length === 0) { + searchApi.reset(); + onClose?.(); + } + }, + [onClose, cb.inputValue] + ); + return ( <>