import React, { useRef, useState, useEffect } from "react"; import styles from "./ToolTip.module.css"; const ToolTip = ({ isOpen, setIsOpen, textAreaRef }) => { const toolTipRef = useRef(null); const handleClickOutside = (event) => { if (toolTipRef.current && !toolTipRef.current.contains(event.target)) { setIsOpen(false); } }; const handleKeyDown = (event) => { if ( isOpen && (event.key === "Escape" || (event.ctrlKey && (event.key === "k" || event.key === "l"))) ) { setIsOpen(false); if (textAreaRef.current) { textAreaRef.current.focus(); } } }; useEffect(() => { document.addEventListener("mousedown", handleClickOutside); document.addEventListener("keydown", handleKeyDown); return () => { document.removeEventListener("mousedown", handleClickOutside); document.removeEventListener("keydown", handleKeyDown); }; }, [isOpen]); return ( isOpen && (
Keyboard Shortcuts
Press Ctrl+K to view keyboard shortcuts.
setIsOpen(false)} > Close