Skip to content

Commit

Permalink
Merge pull request #14312 from rhamilto/OCPBUGS-41610
Browse files Browse the repository at this point in the history
OCPBUGS-41610: restore Spotlight removal on next click
  • Loading branch information
openshift-merge-bot[bot] authored Sep 19, 2024
2 parents ad884d1 + 9090844 commit 46b8993
Showing 1 changed file with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,23 @@ const InteractiveSpotlight: React.FC<InteractiveSpotlightProps> = ({ element })
width,
};

if (!isInViewport(element)) {
element.scrollIntoView({ behavior: 'smooth', block: 'nearest', inline: 'nearest' });
}
const [clicked, setClicked] = React.useState(false);

React.useEffect(() => {
if (!clicked) {
if (!isInViewport(element)) {
element.scrollIntoView({ behavior: 'smooth', block: 'nearest', inline: 'nearest' });
}
const handleClick = () => setClicked(true);
document.addEventListener('click', handleClick);
return () => {
document.removeEventListener('click', handleClick);
};
}
return () => {};
}, [element, clicked]);

if (clicked) return null;

return (
<Popper reference={element} placement="top-start" popperOptions={popperOptions}>
Expand Down

0 comments on commit 46b8993

Please sign in to comment.