Skip to content

Commit

Permalink
Ensure body is scrollable if sidenav is dismissed (#11660)
Browse files Browse the repository at this point in the history
Fixes the body not being scrollable if you have a narrow window, open
the menu, then keep the menu open and make your window wide (causing it
to close).
  • Loading branch information
parlough authored Feb 3, 2025
1 parent 373566f commit ba8c573
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/_sass/components/_sidebar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@ $sidenav-divider-color: #e7e8ed;
display: none;
width: 100%;
z-index: 1010;
background-color: $site-color-white;

@at-root body.open_menu {
overflow-y: hidden;

@media (min-width: 1024px) {
overflow-y: auto;
}

#sidenav {
display: block;
background-color: $site-color-white;
}
}

Expand All @@ -33,6 +37,7 @@ $sidenav-divider-color: #e7e8ed;
top: calc($site-header-height);
overscroll-behavior: auto;
width: 16rem;
background: none;
}

.nav-header {
Expand Down
6 changes: 6 additions & 0 deletions src/content/assets/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ function setupSidenavInteractivity() {
document.body.classList.toggle('open_menu');
});

window.addEventListener('resize', function() {
if (window.innerWidth >= 1024) {
document.body.classList.remove('open_menu');
}
});

document.addEventListener('keydown', function(event) {
if (event.key === 'Escape') {
const activeElement = document.activeElement;
Expand Down

0 comments on commit ba8c573

Please sign in to comment.