Skip to content

Commit d76d7cc

Browse files
ashish10677farhaanbukhsh
authored andcommitted
fix: highlight navbar for hierarchical items
Signed-off-by: Ashish Kumar Mishra <[email protected]> Trigger deploy
1 parent d79cedb commit d76d7cc

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/_includes/js.njk

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
// Add active class to current nav item based on URL
7474
const currentPath = window.location.pathname;
7575
const navLinks = document.querySelectorAll('nav a');
76+
const navLabels = document.querySelectorAll('nav label.nav-link');
7677
7778
navLinks.forEach(link => {
7879
const linkPath = link.getAttribute('href');
@@ -82,6 +83,18 @@
8283
}
8384
});
8485
86+
navLabels.forEach(label => {
87+
const parent = label.closest('li');
88+
const submenuLinks = parent.querySelectorAll('.dropdown-glass a');
89+
submenuLinks.forEach(submenuLink => {
90+
const submenuPath = submenuLink.getAttribute('href');
91+
if (submenuPath && (submenuPath === currentPath ||
92+
(submenuPath !== '/' && currentPath.startsWith(submenuPath)))) {
93+
label.classList.add('active');
94+
}
95+
});
96+
});
97+
8598
// Mobile menu functionality
8699
const mobileMenuCheckbox = document.getElementById('mobile-menu-checkbox');
87100
const mobileMenu = document.getElementById('mobile-menu');

0 commit comments

Comments
 (0)