From ca3b8c6f1200501eebcb02d007723c39be4d97f7 Mon Sep 17 00:00:00 2001 From: Drew Harris Date: Thu, 14 Nov 2024 15:45:43 -0600 Subject: [PATCH] feat: shortcut to toggle component modes --- .../src/utils/hooks/modal-context.tsx | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/clients/search-component/src/utils/hooks/modal-context.tsx b/clients/search-component/src/utils/hooks/modal-context.tsx index ad800111a..fef876e19 100644 --- a/clients/search-component/src/utils/hooks/modal-context.tsx +++ b/clients/search-component/src/utils/hooks/modal-context.tsx @@ -185,6 +185,20 @@ const ModalProvider = ({ props.onOpenChange?.(open); }, [open]); + // Use TAB to alternate modes + useEffect(() => { + const handleKeyDown = (e: KeyboardEvent) => { + if (open && e.key === "Tab") { + e.preventDefault(); + setMode((prevMode) => (prevMode === "chat" ? "search" : "chat")); + } + }; + window.addEventListener("keydown", handleKeyDown); + return () => { + window.removeEventListener("keydown", handleKeyDown); + }; + }, [open]); // Only re-run if open state changes + const search = async (abortController: AbortController) => { if (!query) { setResults([]);