Skip to content

Commit cc2339c

Browse files
authored
Rollup merge of #92803 - jsha:hide-sidebar, r=GuillaumeGomez
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. Fixes #92682 Demo: https://rustdoc.crud.net/jsha/hide-sidebar/std/string/struct.String.html
2 parents 804072f + b71f1fb commit cc2339c

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

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

+4
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,9 @@ function hideThemeButtonState() {
902902
handleClick("help-button", function(ev) {
903903
displayHelp(true, ev);
904904
});
905+
handleClick(MAIN_ID, function() {
906+
hideSidebar();
907+
});
905908

906909
onEachLazy(document.getElementsByTagName("a"), function(el) {
907910
// For clicks on internal links (<A> tags with a hash property), we expand the section we're
@@ -910,6 +913,7 @@ function hideThemeButtonState() {
910913
if (el.hash) {
911914
el.addEventListener("click", function() {
912915
expandSection(el.hash.slice(1));
916+
hideSidebar();
913917
});
914918
}
915919
});

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

+8
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)