Skip to content

Commit b71f1fb

Browse files
committed
Hide mobile sidebar on some clicks
When the user clicks outside the sidebar, the sidebar should close. Also, when the user clicks an internal link in the sidebar, it should close.
1 parent ee5d8d3 commit b71f1fb

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/librustdoc/html/static/js/main.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,9 @@ function hideThemeButtonState() {
897897
handleClick("help-button", function(ev) {
898898
displayHelp(true, ev);
899899
});
900+
handleClick(MAIN_ID, function() {
901+
hideSidebar();
902+
});
900903

901904
onEachLazy(document.getElementsByTagName("a"), function(el) {
902905
// For clicks on internal links (<A> tags with a hash property), we expand the section we're
@@ -905,6 +908,7 @@ function hideThemeButtonState() {
905908
if (el.hash) {
906909
el.addEventListener("click", function() {
907910
expandSection(el.hash.slice(1));
911+
hideSidebar();
908912
});
909913
}
910914
});

src/test/rustdoc-gui/sidebar-mobile.goml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,11 @@ assert-css: (".sidebar-elems", {"display": "block", "left": "0px"})
1818
// When we tab out of the sidebar, close it.
1919
focus: ".search-input"
2020
assert-css: (".sidebar-elems", {"display": "block", "left": "-246px"})
21+
22+
// Open the sidebar menu.
23+
click: ".sidebar-menu"
24+
assert-css: (".sidebar-elems", {"left": "0px"})
25+
26+
// Click elsewhere.
27+
click: "body"
28+
assert-css: (".sidebar-elems", {"left": "-246px"})

0 commit comments

Comments
 (0)