From 4d3f6fd83730873fed0d6f425f9f510624e86a17 Mon Sep 17 00:00:00 2001 From: sivasadobe Date: Tue, 26 Nov 2024 12:27:23 +0530 Subject: [PATCH 1/3] fix(sticky): Adjust sticky section top offset to align with header height initialy --- libs/blocks/section-metadata/sticky-section.js | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/blocks/section-metadata/sticky-section.js b/libs/blocks/section-metadata/sticky-section.js index 2db43622ea..9041e08cfc 100644 --- a/libs/blocks/section-metadata/sticky-section.js +++ b/libs/blocks/section-metadata/sticky-section.js @@ -51,6 +51,7 @@ export default async function handleStickySection(sticky, section) { case 'sticky-top': { const { debounce } = await import('../../utils/action.js'); window.addEventListener('resize', debounce(() => handleTopHeight(section))); + handleTopHeight(section); main.prepend(section); break; } From da054ac4947ec55c152b3f726bfe82d439041a75 Mon Sep 17 00:00:00 2001 From: sivasadobe Date: Tue, 26 Nov 2024 13:40:07 +0530 Subject: [PATCH 2/3] chore: handled header absent --- libs/blocks/section-metadata/sticky-section.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/blocks/section-metadata/sticky-section.js b/libs/blocks/section-metadata/sticky-section.js index 9041e08cfc..cf2b86fe2f 100644 --- a/libs/blocks/section-metadata/sticky-section.js +++ b/libs/blocks/section-metadata/sticky-section.js @@ -2,7 +2,7 @@ import { createTag } from '../../utils/utils.js'; import { getMetadata, getDelayTime } from './section-metadata.js'; function handleTopHeight(section) { - const headerHeight = document.querySelector('header').offsetHeight; + const headerHeight = document.querySelector('header')?.offsetHeight ?? 0; section.style.top = `${headerHeight}px`; } From 00feea1675919281dc029d8d7aea9fb421b3eada Mon Sep 17 00:00:00 2001 From: sivasadobe Date: Mon, 2 Dec 2024 08:32:40 +0530 Subject: [PATCH 3/3] fix: removing hide class when no-delay is present --- .../blocks/section-metadata/sticky-section.js | 1 + test/blocks/section-metadata/mocks/body.html | 24 +++++++++++++++++++ .../section-metadata/section-meta.test.js | 8 +++++++ 3 files changed, 33 insertions(+) diff --git a/libs/blocks/section-metadata/sticky-section.js b/libs/blocks/section-metadata/sticky-section.js index cf2b86fe2f..6457b1adaf 100644 --- a/libs/blocks/section-metadata/sticky-section.js +++ b/libs/blocks/section-metadata/sticky-section.js @@ -33,6 +33,7 @@ function handleStickyPromobar(section, delay) { if ((section.querySelector(':is(.promobar, .notification)').classList.contains('no-delay')) || (delay && section.classList.contains('popup'))) { hasScrollControl = true; + section.classList.remove('hide-sticky-section'); } if (!hasScrollControl && main.children[0] !== section) { stickySectionEl = createTag('div', { class: 'section show-sticky-section' }); diff --git a/test/blocks/section-metadata/mocks/body.html b/test/blocks/section-metadata/mocks/body.html index 923d0be2b1..dbad37b7db 100644 --- a/test/blocks/section-metadata/mocks/body.html +++ b/test/blocks/section-metadata/mocks/body.html @@ -130,6 +130,30 @@ +
+
+
+
+
+
+
+

+ + + +

+

Body M 18/27 Lorem ipsum dolor sit amet, consectetur adipiscing elit. no-delay

+

Call to action

+
+
+
+ +