Skip to content

Commit

Permalink
Adding disable-scroll when localnav is opened
Browse files Browse the repository at this point in the history
  • Loading branch information
bandana147 committed Jan 7, 2025
1 parent 378606d commit 0d197e7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions libs/blocks/global-navigation/global-navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,12 +411,14 @@ class Gnav {

localNav.querySelector('.feds-localnav-title').addEventListener('click', () => {
localNav.classList.toggle('feds-localnav--active');
document.body.classList.toggle('disable-scroll');
const isActive = localNav.classList.contains('feds-localnav--active');
localNav.querySelector('.feds-localnav-title').setAttribute('aria-expanded', isActive);
});

localNav.querySelector('.feds-localnav-curtain').addEventListener('click', (e) => {
trigger({ element: e.currentTarget, event: e, type: 'localNav-curtain' });
document.body.classList.remove('disable-scroll');
});
this.elements.localNav = localNav;
localNavItems[0].querySelector('a').textContent = title.trim();
Expand Down
7 changes: 6 additions & 1 deletion libs/blocks/global-navigation/utilities/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,12 @@ export function setActiveDropdown(elem, type) {
const resetActiveDropdown = () => {
[...document.querySelectorAll(selectors.activeDropdown)]
.forEach((activeDropdown) => activeDropdown.classList.remove(activeClass));
if (!type || type === 'localNav-curtain') {
// Close the localnav if clicked element is not localnav item
if ((!type || type === 'localNav-curtain') ) {
// Remove disable-scroll set by localnav opening
if (document.querySelector('.feds-localnav--active') && !document.querySelector('.feds-toggle[aria-expanded="true"]')) {
document.body.classList.remove('disable-scroll');
}
[...document.querySelectorAll(activeLocalNav)]
.forEach((activeDropdown) => activeDropdown.classList.remove('feds-localnav--active'));
}
Expand Down

0 comments on commit 0d197e7

Please sign in to comment.