Skip to content

Commit

Permalink
header - use list as IntersectionObserver root
Browse files Browse the repository at this point in the history
  • Loading branch information
mucsi96 committed May 10, 2024
1 parent be6895a commit 2673ae6
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions src/Header/Header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,29 @@ import navbarToggleSvg from './navbar-toggle.svg?raw&inline';
injectStyles(styles);

onElementConnected('header[bt] > nav', (navigation) => {
const root = navigation.querySelector(':scope > ul');
const target = root?.querySelector(':scope > li:last-child');

if (!root || !target) {
return;
}

const observer = new IntersectionObserver(
(entries) => {
const entry = entries[0];
if (
!entry.isIntersecting &&
entry.intersectionRect.width !== entry.boundingClientRect.width
) {
if (!entry.isIntersecting) {
navigation.classList.add('overflowing');
} else {
navigation.classList.remove('overflowing');
}
},
{
root: null,
root,
threshold: 1.0,
},
);

const lastLi = navigation.querySelector('ul > li:last-child');

if (!lastLi) {
return;
}

observer.observe(lastLi);
observer.observe(target);
});

onElementConnected(
Expand Down

0 comments on commit 2673ae6

Please sign in to comment.