From 5c1b2623cf0c912530d25eb602a69eade3bbe0b4 Mon Sep 17 00:00:00 2001 From: Bandana Laishram Date: Thu, 28 Nov 2024 16:10:39 +0530 Subject: [PATCH 1/2] Adding active column logic in a large menu --- libs/blocks/global-navigation/global-navigation.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/libs/blocks/global-navigation/global-navigation.js b/libs/blocks/global-navigation/global-navigation.js index 09456cb07a..6038736e51 100644 --- a/libs/blocks/global-navigation/global-navigation.js +++ b/libs/blocks/global-navigation/global-navigation.js @@ -969,7 +969,16 @@ class Gnav { const makeTabActive = (popup) => { if (!popup?.querySelector('.tabs [aria-selected="true"]')) { - setTimeout(() => popup?.querySelector('.tab')?.click(), 100); + const { origin, pathname } = window.location; + const url = `${origin}${pathname}`; + setTimeout(() => { + const activeLink = [ + ...popup.querySelectorAll('a:not([data-modal-hash])'), + ].find((el)=> (el.href === url || el.href.startsWith(`${url}?`) || el.href.startsWith(`${url}#`))); + + const tabIndex = activeLink ? +activeLink.parentNode.id : 0; + popup.querySelectorAll('.tab')[tabIndex]?.click(); + }, 100); } }; From 9c43dd38a6af93e492e1eaa5944c64e82b4090ff Mon Sep 17 00:00:00 2001 From: Bandana Laishram Date: Thu, 28 Nov 2024 16:33:33 +0530 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- libs/blocks/global-navigation/global-navigation.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libs/blocks/global-navigation/global-navigation.js b/libs/blocks/global-navigation/global-navigation.js index 6038736e51..ea44bf0d75 100644 --- a/libs/blocks/global-navigation/global-navigation.js +++ b/libs/blocks/global-navigation/global-navigation.js @@ -974,8 +974,7 @@ class Gnav { setTimeout(() => { const activeLink = [ ...popup.querySelectorAll('a:not([data-modal-hash])'), - ].find((el)=> (el.href === url || el.href.startsWith(`${url}?`) || el.href.startsWith(`${url}#`))); - + ].find((el) => (el.href === url || el.href.startsWith(`${url}?`) || el.href.startsWith(`${url}#`))); const tabIndex = activeLink ? +activeLink.parentNode.id : 0; popup.querySelectorAll('.tab')[tabIndex]?.click(); }, 100);