Skip to content

Commit

Permalink
Fix offcanvas menu open bug
Browse files Browse the repository at this point in the history
Add the click handler to the backdrop element instead of the document to
close the offcanvas menu on mobile devices.

Fixes #1112
  • Loading branch information
lhsazevedo committed Nov 8, 2024
1 parent 070c076 commit 1742dcd
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions js/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -523,13 +523,10 @@ $(document).ready(function () {
};

const closeOffCanvasByClickOutside = (event) => {
if (
!offcanvasElement.contains(event.target) &&
!menuButton.contains(event.target)
) {
closeOffcanvasNav()
if (event.target === backdropElement) {
closeOffcanvasNav();
}
};
}

document
.getElementById("navbar__menu-link")
Expand All @@ -543,7 +540,7 @@ $(document).ready(function () {
.getElementById("navbar__close-button")
.addEventListener("click", closeOffcanvasNav);

document.addEventListener('click', closeOffCanvasByClickOutside);
backdropElement.addEventListener('click', closeOffCanvasByClickOutside);

/*}}}*/

Expand Down

0 comments on commit 1742dcd

Please sign in to comment.