Skip to content

Commit

Permalink
Revert "Removed closeSubMenu behavior - DP-19336"
Browse files Browse the repository at this point in the history
This reverts commit d138bbe.
  • Loading branch information
tom-fleming committed Jul 22, 2020
1 parent 9f0bb57 commit ebbdb13
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions patternlab/styleguide/source/assets/js/modules/mainNavHamburger.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,15 @@ if (null !== menuButton) {

subItems.style.opacity = "0";

itemButton.addEventListener("focus", function(e){
closeSubMenus(item);
});

itemButton.addEventListener("click", function (e) {

closeSubMenus(item);


if (item.classList.contains("submenu-open")) {
item.classList.remove("submenu-open");
itemButton.setAttribute("aria-expanded", "false");
Expand Down Expand Up @@ -320,11 +328,38 @@ function commonOpenMenuTasks() {
}
}

function closeSubMenus(item) {
//Close other open submenus
let siblings = [];
let thisSibling = item.parentNode.firstChild;

while (thisSibling) {
if (thisSibling !== item && thisSibling.nodeType === Node.ELEMENT_NODE)
siblings.push(thisSibling);
thisSibling = thisSibling.nextElementSibling || thisSibling.nextSibling;
}

for (let i = 0; i < siblings.length; i++) {
if (siblings[i].classList.contains("submenu-open")) {

setTimeout(function timeoutFunction() {
siblings[i].querySelector(".js-main-nav-hamburger-content").style.height = "0";
siblings[i].querySelector(".js-main-nav-hamburger-content").classList.add("is-closed");
siblings[i].querySelector(".js-main-nav-hamburger__container").style.opacity = "0";
siblings[i].classList.remove("submenu-open");
siblings[i].querySelector(".js-main-nav-hamburger__top-link").setAttribute("aria-expanded", "false");
}, 500);

}
}
}

// Close menu when utility nav is clicked
if (null !== utilNavWide) {
closeMenu();
}


// Close and reset menu on overlay click
if (null !== menuOverlay) {
menuOverlay.addEventListener("click", function () {
Expand Down

0 comments on commit ebbdb13

Please sign in to comment.