Skip to content

Commit 9d6cb90

Browse files
authored
Merge pull request #572 from vishalvivekm/vishalvivekm-patch-2
fix dropdown behavior to ensure only one menu is open at a time
2 parents fe422d8 + a77cf3c commit 9d6cb90

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

layouts/partials/navbar.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,16 @@
164164
dropdown.addEventListener("click", function (event) {
165165
event.stopPropagation();
166166

167+
// hide any other active dropdowns
168+
const allActiveDropdowns = document.querySelectorAll(".nav-link.current");
169+
allActiveDropdowns.forEach((otherDropdown) => {
170+
if (otherDropdown !== dropdown) {
171+
otherDropdown.classList.remove("current");
172+
otherDropdown.nextElementSibling.classList.remove("show");
173+
otherDropdown.nextElementSibling.style.visibility = "hidden";
174+
}
175+
});
176+
167177
if (dropdown.classList.contains("current")) {
168178
dropdown.classList.remove("current");
169179
dropdownMenu.classList.remove("show");

0 commit comments

Comments
 (0)