fix(core): 🐛 incorrect sticky header class assignment

This commit is contained in:
alistair3149 2024-05-25 19:53:17 -04:00
parent 27bca0fc66
commit af3d72ad75
No known key found for this signature in database

View file

@ -34,8 +34,8 @@ function initStickyHeader( document ) {
const addScrollDownClass = toggleScrollClass( SCROLL_UP_CLASS, SCROLL_DOWN_CLASS ); const addScrollDownClass = toggleScrollClass( SCROLL_UP_CLASS, SCROLL_DOWN_CLASS );
const addScrollUpClass = toggleScrollClass( SCROLL_DOWN_CLASS, SCROLL_UP_CLASS ); const addScrollUpClass = toggleScrollClass( SCROLL_DOWN_CLASS, SCROLL_UP_CLASS );
const toggleStickyClass = () => { const toggleStickyClass = ( state ) => {
return ( state ) => { return () => {
window.requestAnimationFrame( () => { window.requestAnimationFrame( () => {
document.body.classList.toggle( STICKY_CLASS, state ); document.body.classList.toggle( STICKY_CLASS, state );
} ); } );
@ -45,8 +45,9 @@ function initStickyHeader( document ) {
initDirectionObserver( addScrollDownClass, addScrollUpClass, 10 ); initDirectionObserver( addScrollDownClass, addScrollUpClass, 10 );
const sentinel = document.getElementById( STICKY_SENTINEL_ID ); const sentinel = document.getElementById( STICKY_SENTINEL_ID );
const shouldStickyHeader = sentinel && getComputedStyle( sentinel ).getPropertyValue( 'display' ) !== 'none';
if ( sentinel && getComputedStyle( sentinel ).getPropertyValue( 'display' ) !== 'none' ) { if ( shouldStickyHeader ) {
const observer = initIntersectionObserver( toggleStickyClass( true ), toggleStickyClass( false ) ); const observer = initIntersectionObserver( toggleStickyClass( true ), toggleStickyClass( false ) );
observer.observe( sentinel ); observer.observe( sentinel );
} }