Skip to content

Commit

Permalink
update behavior adn code
Browse files Browse the repository at this point in the history
  • Loading branch information
mirnawong1 committed Dec 15, 2023
1 parent 203cb05 commit c9ce546
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions website/src/components/detailsToggle/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<div className='detailsToggle'>
Expand Down

0 comments on commit c9ce546

Please sign in to comment.