Skip to content

Commit

Permalink
Cls fix for promo
Browse files Browse the repository at this point in the history
  • Loading branch information
bandana147 committed Jan 8, 2025
1 parent d704a97 commit 3d4ba56
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
4 changes: 2 additions & 2 deletions libs/blocks/global-navigation/features/aside/aside.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { loadBlock, decorateAutoBlock } from '../../../../utils/utils.js';
import { toFragment, lanaLog } from '../../utilities/utilities.js';
import { processTrackingLabels } from '../../../../martech/attributes.js';

export default async function decorateAside({ localNav, promoPath } = {}) {
export default async function decorateAside({ fedsPromoWrapper, promoPath } = {}) {
const onError = () => {
localNav?.classList.remove('has-promo');
fedsPromoWrapper.remove();
lanaLog({ message: 'Gnav Promo fragment not replaced, potential CLS' });
return '';
};
Expand Down
1 change: 1 addition & 0 deletions libs/blocks/global-navigation/global-navigation.css
Original file line number Diff line number Diff line change
Expand Up @@ -1204,6 +1204,7 @@ header.new-nav .feds-breadcrumbs li:first-child:not(:nth-last-child(-n+3)):after
position: sticky;
top: 0;
z-index: 11;
height: var(--global-height-navPromo);
}

@keyframes slideright {
Expand Down
13 changes: 7 additions & 6 deletions libs/blocks/global-navigation/global-navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,8 @@ class Gnav {
document.body.classList.remove('disable-scroll');
enableMobileScroll();
});
const promo = getMetadata('gnav-promo-source');
if (promo?.length) localNav.classList.add('has-promo');
const promo = document.querySelector('.feds-promo-aside-wrapper');
if (promo) localNav.classList.add('has-promo');
this.elements.localNav = localNav;
localNavItems[0].querySelector('a').textContent = title.trim();
const isAtTop = () => {
Expand Down Expand Up @@ -937,16 +937,17 @@ class Gnav {
decorateAside = async () => {
this.elements.aside = '';
const promoPath = getMetadata('gnav-promo-source');

if (!promoPath) {
this.elements.localNav.classList.remove('has-promo');
const fedsPromoWrapper = document.querySelector('.feds-promo-aside-wrapper');
fedsPromoWrapper?.remove();
return this.elements.aside;
}

const { default: decorate } = await import('./features/aside/aside.js');
if (!decorate) return this.elements.aside;
this.elements.aside = await decorate({ headerElem: this.block, promoPath });
this.block.before(toFragment`<div class="feds-promo-aside-wrapper">${this.elements.aside}</div>`)
const fedsPromoWrapper = document.querySelector('.feds-promo-aside-wrapper');
this.elements.aside = await decorate({ localNavElem: this.elements.localNav, fedsPromoWrapper, promoPath });
fedsPromoWrapper.append(this.elements.aside);
};

decorateBrand = () => this.decorateGenericLogo({
Expand Down
5 changes: 5 additions & 0 deletions libs/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,11 @@ async function decorateHeader() {
header.after(localNavWrapper);
}
if (breadcrumbs) header.append(breadcrumbs);
const promo = getMetadata('gnav-promo-source');
if (promo?.length) {
const fedsPromoWrapper = createTag('div', { class: 'feds-promo-aside-wrapper' });
header.before(fedsPromoWrapper);
}
}

async function decorateIcons(area, config) {
Expand Down

0 comments on commit 3d4ba56

Please sign in to comment.