Skip to content

Commit

Permalink
fix mobile to desktop nav bug
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanlamoureux committed Dec 7, 2023
1 parent 63eca5a commit 16dbb6a
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions components/mobileNav.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class mobileNav extends HTMLElement {
`

this.updateNavWrapperClass()
this.setActiveLink()
}

updateNavWrapperClass() {
Expand All @@ -71,6 +72,21 @@ class mobileNav extends HTMLElement {
navWrapper.classList.add('about-nav-wrapper')
}
}

setActiveLink() {
const currentPath = window.location.pathname
const links = this.querySelectorAll('.link')

links.forEach(link => {
const href = link.getAttribute('href')
// Check if the href matches either the root path or index.html
if (href === currentPath || (currentPath === '/' && href === '/')) {
link.classList.add('is-active')
} else {
link.classList.remove('is-active')
}
})
}
}

customElements.define('mobile-nav', mobileNav)

0 comments on commit 16dbb6a

Please sign in to comment.