Skip to content

Commit

Permalink
bugfix: scroll listeners with passive required (#707)
Browse files Browse the repository at this point in the history
* bugfix: scroll listeners with passive required

* also fix footer height measurements
  • Loading branch information
wibjorn authored Oct 24, 2024
1 parent 5fb69be commit 80cb7aa
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/chilled-lemons-greet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@microsoft/atlas-js': patch
---

Layout to use passive scroll listeners to measure visible header height
5 changes: 5 additions & 0 deletions .changeset/rare-zoos-exercise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@microsoft/atlas-js': patch
---

Measurement for atlas-footer-visible-height was not correct.
15 changes: 14 additions & 1 deletion js/src/behaviors/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ const setLayoutCssVariables = () => {
const footerHeight = footer?.clientHeight || 0;
const footerCssProp = footerHeight ? `${footerHeight}px` : '0px';
const footerY = footer?.getBoundingClientRect().y || 0; // determine if header and footer are visible, assign visible heights as well
const visibleFooterHeight = Math.round(Math.max(0, footerY + footerHeight));

const visibleFooterHeight = Math.round(
footerY < window.innerHeight ? Math.min(window.innerHeight - footerY, footerHeight) : 0
);
const visibleFooterCssProp = `${visibleFooterHeight}px`;

root.style.setProperty('--window-inner-height', `${window.innerHeight}px`, 'important');
Expand Down Expand Up @@ -42,4 +45,14 @@ export function initLayout() {
root.style.setProperty('--window-inner-height', `${window.innerHeight}px`);

window.addEventListener('DOMContentLoaded', setLayoutCssVariables, { passive: true });

// determine if header/footer are visible below the top of the viewport

window.addEventListener(
'scroll',
() => window.dispatchEvent(new CustomEvent('atlas-layout-change-event')),
{
passive: true
}
);
}

0 comments on commit 80cb7aa

Please sign in to comment.