Skip to content

Commit

Permalink
rustdoc: fix resize trouble with mobile
Browse files Browse the repository at this point in the history
  • Loading branch information
notriddle committed Oct 11, 2023
1 parent 77fa09d commit fd9f1a7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/librustdoc/html/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1305,6 +1305,7 @@ href="https://doc.rust-lang.org/${channel}/rustdoc/how-to-read-rustdoc.html\
// at most 400px. Otherwise, it would start out at the default size, then
// grabbing the resize handle would suddenly cause it to jank to
// its contraint-generated maximum.
const RUSTDOC_MOBILE_BREAKPOINT = 700;
const BODY_MIN = 400;
// At half-way past the minimum size, vanish the sidebar entirely
const SIDEBAR_VANISH_THRESHOLD = SIDEBAR_MIN / 2;
Expand Down Expand Up @@ -1474,6 +1475,9 @@ href="https://doc.rust-lang.org/${channel}/rustdoc/how-to-read-rustdoc.html\
}
// Respond to the window resize event.
window.addEventListener("resize", () => {
if (window.innerWidth < RUSTDOC_MOBILE_BREAKPOINT) {
return;
}
stopResize();
if (desiredSidebarSize >= (window.innerWidth - BODY_MIN)) {
changeSidebarSize(window.innerWidth - BODY_MIN);
Expand Down
4 changes: 4 additions & 0 deletions tests/rustdoc-gui/sidebar-resize-window.goml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ wait-for-property: (".sidebar", {"clientWidth": 500}, [NEAR])
// make the window small enough that the sidebar has to shrink
set-window-size: (750, 600)
wait-for-property: (".sidebar", {"clientWidth": 350}, [NEAR])
assert-local-storage: {"rustdoc-desktop-sidebar-width": "350"}
set-window-size: (400, 600)
wait-for-css: (".sidebar", {"display": "block", "left": "-1000px"})
assert-local-storage: {"rustdoc-desktop-sidebar-width": "350"}

// grow the window again to make the sidebar bigger
set-window-size: (1280, 600)
Expand Down

0 comments on commit fd9f1a7

Please sign in to comment.