From 578fbd78cdb2b77274da3546fcb98a74d13762c1 Mon Sep 17 00:00:00 2001 From: Bandana Laishram Date: Fri, 10 Jan 2025 13:20:12 +0530 Subject: [PATCH 1/2] Adding support for localnav's first item as dropdown --- libs/blocks/global-navigation/global-navigation.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libs/blocks/global-navigation/global-navigation.js b/libs/blocks/global-navigation/global-navigation.js index 205ba16086..8db8dac32b 100644 --- a/libs/blocks/global-navigation/global-navigation.js +++ b/libs/blocks/global-navigation/global-navigation.js @@ -405,7 +405,7 @@ class Gnav { decorateLocalNav = async () => { if (!this.isLocalNav()) return; const localNavItems = this.elements.navWrapper.querySelector('.feds-nav').querySelectorAll('.feds-navItem:not(.feds-navItem--section, .feds-navItem--mobile-only)'); - const firstElem = localNavItems[0]?.querySelector('a'); + const firstElem = localNavItems[0]?.querySelector('a') || localNavItems[0]?.querySelector('button'); if (!firstElem) { lanaLog({ message: 'GNAV: Incorrect authoring of localnav found.', tags: 'errorType=info,module=gnav' }); return; @@ -428,7 +428,7 @@ class Gnav { localNavItems.forEach((elem, idx) => { const clonedItem = elem.cloneNode(true); - const link = clonedItem.querySelector('a'); + const link = clonedItem.querySelector('a') || localNavItems[0]?.querySelector('button'); if (idx === 0) { localNav.querySelector('.feds-localnav-title').innerText = title.trim(); @@ -456,7 +456,7 @@ class Gnav { 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(); + firstElem.textContent = title.trim(); const isAtTop = () => { const rect = this.elements.localNav.getBoundingClientRect(); // note: ios safari changes between -0.34375, 0, and 0.328125 From fe99f90178ce611deb2362ad138a6006418fa33c Mon Sep 17 00:00:00 2001 From: Bandana Laishram Date: Fri, 10 Jan 2025 13:58:42 +0530 Subject: [PATCH 2/2] Removing localnav wrapper if localnav fails to render --- libs/blocks/global-navigation/global-navigation.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/libs/blocks/global-navigation/global-navigation.js b/libs/blocks/global-navigation/global-navigation.js index 8db8dac32b..fb194bc9f8 100644 --- a/libs/blocks/global-navigation/global-navigation.js +++ b/libs/blocks/global-navigation/global-navigation.js @@ -402,13 +402,19 @@ class Gnav { `; }; + removeLocalNav = () => { + lanaLog({ message: 'Gnav Localnav was removed, potential CLS' }); + document.querySelector('.feds-localnav')?.remove(); + return; + } + decorateLocalNav = async () => { - if (!this.isLocalNav()) return; + if (this.isLocalNav()) this.removeLocalNav(); const localNavItems = this.elements.navWrapper.querySelector('.feds-nav').querySelectorAll('.feds-navItem:not(.feds-navItem--section, .feds-navItem--mobile-only)'); const firstElem = localNavItems[0]?.querySelector('a') || localNavItems[0]?.querySelector('button'); if (!firstElem) { lanaLog({ message: 'GNAV: Incorrect authoring of localnav found.', tags: 'errorType=info,module=gnav' }); - return; + this.removeLocalNav(); } const [title, navTitle = ''] = this.getOriginalTitle(firstElem); let localNav = document.querySelector('.feds-localnav');