fix: close burger menu not closing when clicking outside the nav or on a link
This commit is contained in:
parent
a3b10fd52e
commit
1c8a92bddf
|
|
@ -4,6 +4,8 @@ class NavBar extends HTMLElement {
|
|||
connectedCallback() {
|
||||
document.addEventListener("scroll", this.onScroll.bind(this))
|
||||
this.addEventListener('transitionend', this.onTransitionEnd.bind(this))
|
||||
this.addEventListener('click', this.onClick.bind(this))
|
||||
document.addEventListener('click', this.onDocumentClick.bind(this))
|
||||
this.onScroll()
|
||||
}
|
||||
|
||||
|
|
@ -25,6 +27,18 @@ class NavBar extends HTMLElement {
|
|||
this.classList.remove("nav-bar__docking")
|
||||
}
|
||||
}
|
||||
|
||||
onClick(evt) {
|
||||
if(evt.target.matches('a')) {
|
||||
this.classList.remove('nav-bar__open')
|
||||
}
|
||||
}
|
||||
|
||||
onDocumentClick(evt) {
|
||||
if(!this.contains(evt.target)) {
|
||||
this.classList.remove('nav-bar__open')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ToggleNavBarButton extends HTMLElement {
|
||||
|
|
|
|||
Loading…
Reference in New Issue