Skip to content

Commit ad8ae3d

Browse files
committedMar 6, 2025
Add event listener to close mobile menu on primary mobile menu toggle click
1 parent b85bb2d commit ad8ae3d

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed
 

‎tbx/static_src/javascript/components/mobile-menu.js

+12
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ class MobileMenu {
77
this.node = node;
88
this.body = document.querySelector('body');
99
this.mobileMenu = document.querySelector('[data-mobile-menu]');
10+
this.primaryMobileToggle = document.querySelector(
11+
'[data-primary-mobile-menu-toggle]',
12+
);
1013
this.lastMenuItem = document.querySelector(
1114
'[data-last-menu-item-mobile]',
1215
);
@@ -33,6 +36,15 @@ class MobileMenu {
3336
}
3437
});
3538

39+
// Close the mobile menu if the primary mobile menu toggle is clicked
40+
if (this.primaryMobileToggle) {
41+
this.primaryMobileToggle.addEventListener('click', () => {
42+
if (this.state.open) {
43+
this.close();
44+
}
45+
});
46+
}
47+
3648
// Close the mobile menu when the focus moves away from the last item in the top level
3749
if (this.lastMenuItem === null) {
3850
return;

0 commit comments

Comments
 (0)