Skip to content

Commit 5590384

Browse files
authored
Add inert to main content when mobile menu is open (#3343)
1 parent feacb7d commit 5590384

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

src/static/js/almanac.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ function handleNavMenu() {
155155
function handleMobileMenu() {
156156
var menuBtn = document.querySelector('.menu-btn');
157157
var menuNav = document.querySelector('#menu');
158+
var main = document.querySelector('main');
159+
var footer = document.querySelector('footer');
158160

159161
function toggleNavMenu() {
160162
var menuOpen = document.body.classList.toggle('menu-open');
@@ -163,6 +165,10 @@ function handleMobileMenu() {
163165
var ariaLabel = menuOpen ? menuBtn.getAttribute('data-close-text') : menuBtn.getAttribute('data-open-text');
164166
menuBtn.setAttribute('aria-label', ariaLabel);
165167

168+
// Toogle inert to keep focus in the menu and header
169+
main.toggleAttribute('inert');
170+
footer.toggleAttribute('inert');
171+
166172
/* When you open the menu, add an event listener to close it when clicking outside the menu area */
167173
/* Remove it on closing the menu */
168174
if (menuBtn.getAttribute('aria-expanded') === 'true') {

0 commit comments

Comments
 (0)