Skip to content

Commit

Permalink
feat: shortcut to toggle component modes
Browse files Browse the repository at this point in the history
  • Loading branch information
drew-harris committed Nov 14, 2024
1 parent 213252b commit ca3b8c6
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions clients/search-component/src/utils/hooks/modal-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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([]);
Expand Down

0 comments on commit ca3b8c6

Please sign in to comment.