Skip to content

Commit 94ef2b5

Browse files
committed
Auto-hide navigation on link click
Hide navigation sidebar when clicking anchor links on mobile devices. Previously, anchor links would change the page but the navigation sidebar would block the view.
1 parent dba9474 commit 94ef2b5

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

lib/rdoc/generator/template/darkfish/js/darkfish.js

+13
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,22 @@ function hookSidebar() {
106106
}
107107
}
108108

109+
function hookAnchorLinks() {
110+
document.addEventListener('click', (e) => {
111+
const anchor = e.target.closest('a[href^="#"]');
112+
if (anchor && window.matchMedia("(max-width: 1023px)").matches) {
113+
const navigation = document.querySelector('#navigation');
114+
const navigationToggle = document.querySelector('#navigation-toggle');
115+
navigation.hidden = true;
116+
navigationToggle.ariaExpanded = false;
117+
}
118+
});
119+
}
120+
109121
document.addEventListener('DOMContentLoaded', function() {
110122
hookSourceViews();
111123
hookSearch();
112124
hookFocus();
113125
hookSidebar();
126+
hookAnchorLinks();
114127
});

0 commit comments

Comments
 (0)