diff --git a/src/components/DashboardHeader.tsx b/src/components/DashboardHeader.tsx index 764b691c..3810a68e 100644 --- a/src/components/DashboardHeader.tsx +++ b/src/components/DashboardHeader.tsx @@ -70,8 +70,9 @@ export default function DashboardHeader() {
+
- +
diff --git a/src/components/KeyboardShortcuts.tsx b/src/components/KeyboardShortcuts.tsx index 59577f18..724eb2cb 100644 --- a/src/components/KeyboardShortcuts.tsx +++ b/src/components/KeyboardShortcuts.tsx @@ -10,6 +10,7 @@ export default function KeyboardShortcuts() { const [announcement, setAnnouncement] = useState(""); const { theme, toggleTheme } = useTheme(); const keyboardToggleRef = useRef(false); + const shortcutsRef = useRef(null); useEffect(() => { if (keyboardToggleRef.current && theme !== undefined) { @@ -59,17 +60,33 @@ export default function KeyboardShortcuts() { }; }, [toggleTheme]); + useEffect(() => { + function handleClickOutside(e: MouseEvent) { + if ( + shortcutsRef.current && + !shortcutsRef.current.contains(e.target as Node) + ) { + setIsOpen(false); + } + } + + document.addEventListener("mousedown", handleClickOutside); + return () => document.removeEventListener("mousedown", handleClickOutside); + }, []); + return ( - <> +
{announcement}
setIsOpen(false)} /> - +
); } \ No newline at end of file diff --git a/src/components/ShortcutsModal.tsx b/src/components/ShortcutsModal.tsx index be910d6a..07ec8415 100644 --- a/src/components/ShortcutsModal.tsx +++ b/src/components/ShortcutsModal.tsx @@ -19,16 +19,17 @@ const SHORTCUTS: ShortcutItem[] = [ { key: "?", action: "Show shortcuts" }, ]; -export default function ShortcutsModal({ isOpen, onClose}: ShortcutsModalProps) { +export default function ShortcutsModal({ + isOpen, + onClose, +}: ShortcutsModalProps) { const modalRef = useRef(null); const closeBtnRef = useRef(null); useEffect(() => { if (!isOpen) return; - if (closeBtnRef.current) { - closeBtnRef.current.focus(); - } + closeBtnRef.current?.focus(); const handleKeyDown = (e: KeyboardEvent) => { if (e.key === "Escape") { @@ -48,16 +49,12 @@ export default function ShortcutsModal({ isOpen, onClose}: ShortcutsModalProps) const firstElement = focusableElements[0]; const lastElement = focusableElements[focusableElements.length - 1]; - if (e.shiftKey) { - if (document.activeElement === firstElement) { - lastElement.focus(); - e.preventDefault(); - } - } else { - if (document.activeElement === lastElement) { - firstElement.focus(); - e.preventDefault(); - } + if (e.shiftKey && document.activeElement === firstElement) { + lastElement.focus(); + e.preventDefault(); + } else if (!e.shiftKey && document.activeElement === lastElement) { + firstElement.focus(); + e.preventDefault(); } } }; @@ -72,52 +69,53 @@ export default function ShortcutsModal({ isOpen, onClose}: ShortcutsModalProps) return (
-
e.stopPropagation()} - > -
- - -
- -
- {SHORTCUTS.map((item) => ( -
- {item.action} - - {item.key} - -
- ))} -
- -
- +
+ +
+ {SHORTCUTS.map((item) => ( +
- Got it - -
+ + {item.action} + + + {item.key} + +
+ ))} +
+ +
+
);