Skip to content

Commit

Permalink
Excluding modals from Active link check (#1942)
Browse files Browse the repository at this point in the history
* Fix: Excluding modals from Active link check

---------

Co-authored-by: Bandana Laishram <blaishram@Bandanas-MacBook-Pro.local>
  • Loading branch information
bandana147 and Bandana Laishram authored Mar 19, 2024
1 parent dc2f291 commit e909bc6
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions libs/blocks/global-navigation/utilities/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,12 +264,10 @@ export const [hasActiveLink, setActiveLink, getActiveLink] = (() => {
(area) => {
if (hasActiveLink() || !(area instanceof HTMLElement)) return null;
const { origin, pathname } = window.location;
let activeLink;

[`${origin}${pathname}`, pathname].forEach((path) => {
if (activeLink) return;
activeLink = area.querySelector(`a[href = '${path}'], a[href ^= '${path}?'], a[href ^= '${path}#']`);
});
const url = `${origin}${pathname}`;
const activeLink = [
...area.querySelectorAll('a:not([data-modal-hash])'),
].find((el) => (el.href === url || el.href.startsWith(`${url}?`) || el.href.startsWith(`${url}#`)));

if (!activeLink) return null;

Expand Down

0 comments on commit e909bc6

Please sign in to comment.