Skip to content

Commit

Permalink
Update SearchIcons.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Janpot committed Sep 29, 2024
1 parent c6cdb93 commit 098a40e
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions docs/data/material/components/material-icons/SearchIcons.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,17 @@ function Icon(props) {
const [isVisible, setIsVisible] = React.useState(false);

React.useEffect(() => {
const margin = 200;
const observer = new IntersectionObserver(
(entries) => {
setIsVisible(entries[0].isIntersecting);
// `isIntersecting` is not working correctly on Chrome
const clientRect = entries[0].target.getBoundingClientRect();
const isIntersecting =
clientRect.top < window.innerHeight + margin &&
clientRect.bottom > -margin;
setIsVisible(isIntersecting);
},
{ rootMargin: `200px 0px` },
{ rootMargin: `${margin}px 0px` },
);
observer.observe(rootRef.current);
return () => {
Expand Down

0 comments on commit 098a40e

Please sign in to comment.