From c9ce5465bd5464326830ad61fbd13beae48b3c53 Mon Sep 17 00:00:00 2001 From: mirnawong1 Date: Fri, 15 Dec 2023 15:24:18 -0500 Subject: [PATCH] update behavior adn code --- website/src/components/detailsToggle/index.js | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/website/src/components/detailsToggle/index.js b/website/src/components/detailsToggle/index.js index 90464328f8b..ba53192e54b 100644 --- a/website/src/components/detailsToggle/index.js +++ b/website/src/components/detailsToggle/index.js @@ -7,29 +7,29 @@ function detailsToggle({ children, alt_header = null }) { const [hoverTimeout, setHoverTimeout] = useState(null); const handleToggleClick = () => { - setOn(false); - setHoverActive(isOn); // Toggle hover activation based on current state - }; + setHoverActive(true); // Disable hover when clicked + setOn(current => !current); // Toggle the current state +}; - const handleMouseEnter = () => { - if (!hoverActive) return; // Ignore hover if disabled - const timeout = setTimeout(() => { - setOn(true); - }, 500); // 500ms delay - setHoverTimeout(timeout); - }; +const handleMouseEnter = () => { + if (isOn) return; // Ignore hover if already open + setHoverActive(true); // Enable hover + const timeout = setTimeout(() => { + if (hoverActive) setOn(true); + }, 500); + setHoverTimeout(timeout); +}; - const handleMouseLeave = () => { - if (hoverActive && !isOn) { +const handleMouseLeave = () => { + if (!isOn) { clearTimeout(hoverTimeout); setOn(false); - // isOn (false); can't be used here but setOn triggers a re-render - } - }; + } +}; - useEffect(() => { - return () => clearTimeout(hoverTimeout); - }, [hoverTimeout]); +useEffect(() => { + return () => clearTimeout(hoverTimeout); +}, [hoverTimeout]); return (