Skip to content

Commit

Permalink
close menu if clicking on grid-icon
Browse files Browse the repository at this point in the history
Signed-off-by: Vivek Vishal <[email protected]>
  • Loading branch information
vishalvivekm authored Oct 24, 2024
1 parent 47d2a6d commit 5fd1fc9
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions layouts/partials/navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,15 @@
dropdown.addEventListener("click", function (event) {
event.stopPropagation();

closeOtherDropdowns(dropdownId);
if (dropdown.classList.contains("current")) {
dropdown.classList.remove("current");
dropdownMenu.classList.remove("show");
dropdownMenu.style.visibility = "hidden";
} else {
dropdown.classList.toggle("current");
dropdownMenu.classList.toggle("show");
dropdownMenu.style.visibility = "visible";
}
});

document.body.addEventListener('click', function() {
Expand All @@ -174,20 +179,7 @@
}
});
}
function closeOtherDropdowns(currentDropdownId) {
const allDropdowns = document.querySelectorAll(".nav-item.dropdown");

// close all dropdowns except current one
allDropdowns.forEach(function (dropdown) {
if (dropdown.querySelector(`#${currentDropdownId}`) === null) {
dropdown.classList.remove("current");
const dropdownMenu = dropdown.querySelector(".dropdown-menu");
if (dropdownMenu) {
dropdownMenu.classList.remove("show");
}
}
});
}

setupDropdown("productsDropdown");
// console.log(window.location.pathname == "/cloud/");
Expand Down

0 comments on commit 5fd1fc9

Please sign in to comment.