Skip to content

Commit 93835ec

Browse files
minkyngkmcwarnermm
andauthored
Fix navigation not closing on large screens (#7591)
Co-authored-by: Carrie Warner (Mattermost) <74422101+cwarnermm@users.noreply.github.com>
1 parent 6d1586a commit 93835ec

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

source/_static/js/myscript-v1.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ $(document).ready(function () {
2222
}
2323

2424
// Listen for changes in the theme preference
25-
window.matchMedia('(prefers-color-scheme: dark)').addListener(function (e) {
25+
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', function (e) {
2626
// Only update the theme based on prefers-color-scheme if 'data-theme' is 'auto' or not set
2727
if (
2828
!$('body').attr('data-theme') ||
@@ -149,4 +149,18 @@ $(document).ready(function () {
149149
document.body.classList.toggle('nav-open');
150150
document.getElementById('navigation').classList.toggle('nav-is-active');
151151
});
152+
153+
// Remove classes to close the nav if screen size is larger than 992px
154+
function closeNav() {
155+
if (window.innerWidth > 992) {
156+
document.body.classList.remove('nav-open');
157+
document.getElementById('navigation').classList.remove('nav-is-active');
158+
hamburger.classList.remove('is-active');
159+
}
160+
}
161+
162+
closeNav();
163+
164+
$(window).on('resize', closeNav);
165+
152166
});

0 commit comments

Comments
 (0)