Skip to content

Commit

Permalink
Fix corner cases when dealing with mobile mode
Browse files Browse the repository at this point in the history
  • Loading branch information
notriddle committed Dec 20, 2023
1 parent 34984a6 commit 9566db1
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 17 deletions.
15 changes: 9 additions & 6 deletions src/librustdoc/html/static/css/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -1560,6 +1560,9 @@ a.tooltip:hover::after {
left: 8px;
z-index: 101;
}
.hide-sidebar .src #sidebar-button {
position: static;
}
#settings-menu > a, #help-button > a, #sidebar-button > a {
display: flex;
align-items: center;
Expand Down Expand Up @@ -1896,6 +1899,12 @@ in src-script.js and main.js
.src .search-form {
margin-left: 40px;
}
.hide-sidebar .search-form {
margin-left: 32px;
}
.hide-sidebar .src .search-form {
margin-left: 0;
}

.sidebar.shown,
.src-sidebar-expanded .src .sidebar,
Expand Down Expand Up @@ -2020,12 +2029,6 @@ in src-script.js and main.js
.src .src-sidebar-title {
padding-top: 0;
}
.hide-sidebar #sidebar-button {
position: static;
}
.src #sidebar-button {
position: fixed;
}

/* Position of the "[-]" element. */
details.toggle:not(.top-doc) > summary {
Expand Down
18 changes: 7 additions & 11 deletions src/librustdoc/html/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1519,18 +1519,14 @@ href="https://doc.rust-lang.org/${channel}/rustdoc/read-documentation/search.htm
// and it can be activated by resizing the sidebar into nothing.
const sidebarButton = document.getElementById("sidebar-button");
if (sidebarButton) {
if (document.querySelector(".rustdoc.src")) {
sidebarButton.addEventListener("click", e => {
sidebarButton.addEventListener("click", e => {
removeClass(document.documentElement, "hide-sidebar");
updateLocalStorage("hide-sidebar", "false");
if (document.querySelector(".rustdoc.src")) {
window.rustdocToggleSrcSidebar();
e.preventDefault();
});
} else {
sidebarButton.addEventListener("click", e => {
removeClass(document.documentElement, "hide-sidebar");
updateLocalStorage("hide-sidebar", "false");
e.preventDefault();
});
}
}
e.preventDefault();
});
}

// Pointer capture.
Expand Down
28 changes: 28 additions & 0 deletions tests/rustdoc-gui/sidebar-resize-setting.goml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,31 @@ wait-for-css: ("#settings", {"display": "block"})
assert-property: ("#hide-sidebar", {"checked": "true"})
click: "#hide-sidebar"
wait-for-css: (".sidebar", {"display": "block"})

// Verify that hiding the sidebar hides the source sidebar
// and puts the button in static position mode on mobile
go-to: "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html"
set-window-size: (600, 600)
focus: "#settings-menu a"
press-key: "Enter"
wait-for-css: ("#settings", {"display": "block"})
wait-for-css: ("#sidebar-button", {"position": "fixed"})
store-position: ("#sidebar-button", {
"y": sidebar_button_y,
"x": sidebar_button_x,
})
assert-property: ("#hide-sidebar", {"checked": "false"})
click: "#hide-sidebar"
wait-for-css: (".sidebar", {"display": "none"})
wait-for-css: ("#sidebar-button", {"position": "static"})
assert-position: ("#sidebar-button", {
"y": |sidebar_button_y|,
"x": |sidebar_button_x|,
})
assert-property: ("#hide-sidebar", {"checked": "true"})
press-key: "Escape"
// Clicking the sidebar button should work, and implicitly re-enable
// the persistent navigation bar
wait-for-css: ("#settings", {"display": "none"})
click: "#sidebar-button"
wait-for-css: (".sidebar", {"display": "block"})
1 change: 1 addition & 0 deletions tests/rustdoc-gui/src/theme_css/custom-theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
--code-attribute-color: #999;
--toggles-color: #999;
--toggle-filter: none;
--mobile-sidebar-menu-filter: none;
--search-input-focused-border-color: #66afe9;
--copy-path-button-color: #999;
--copy-path-img-filter: invert(50%);
Expand Down

0 comments on commit 9566db1

Please sign in to comment.