Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MWPW-162722: Sticky promo banner loading issue #3263

Merged
merged 3 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion libs/blocks/section-metadata/sticky-section.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
}

Expand Down Expand Up @@ -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' });
Expand All @@ -51,6 +52,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;
}
Expand Down
24 changes: 24 additions & 0 deletions test/blocks/section-metadata/mocks/body.html
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,30 @@
</div>
</div>
</div>
<div class="section sticky-bottom-no-delay">
<div class="aside notification small center promobar no-delay">
<div>
<div data-valign="middle"></div>
</div>
<div>
<div data-valign="middle">
<p>
<picture>
<img loading="lazy" alt="" src="" width="750" height="738">
</picture>
</p>
<p><strong>Body M 18/27 Lorem ipsum dolor sit amet, consectetur adipiscing elit. no-delay</strong></p>
<p><strong><a href="">Call to action</a></strong></p>
</div>
</div>
</div>
<div class="section-metadata">
<div>
<div>style</div>
<div>sticky bottom, dark</div>
</div>
</div>
</div>
<div>
<div class="section-metadata">
<div>
Expand Down
8 changes: 8 additions & 0 deletions test/blocks/section-metadata/section-meta.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ describe('Section Metdata', () => {
expect(sec.classList.contains('hide-sticky-section')).not.to.be.true;
});

it('add promobar behaviour to be visible when no-delay', async () => {
const main = document.querySelector('main');
const sec = document.querySelector('.section.sticky-bottom-no-delay .promobar').closest('.section');
const sm = sec.querySelector('.section-metadata');
await init(sm);
expect(main.lastElementChild.classList.contains('hide-sticky-section')).to.be.false;
});

it('should calculate the top position based on header height', async () => {
const sec = document.querySelector('.section.sticky-top');
const header = document.createElement('header');
Expand Down
Loading