Skip to content

Commit fd9f1a7

Browse files
committed
rustdoc: fix resize trouble with mobile
1 parent 77fa09d commit fd9f1a7

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

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

+4
Original file line numberDiff line numberDiff line change
@@ -1305,6 +1305,7 @@ href="https://doc.rust-lang.org/${channel}/rustdoc/how-to-read-rustdoc.html\
13051305
// at most 400px. Otherwise, it would start out at the default size, then
13061306
// grabbing the resize handle would suddenly cause it to jank to
13071307
// its contraint-generated maximum.
1308+
const RUSTDOC_MOBILE_BREAKPOINT = 700;
13081309
const BODY_MIN = 400;
13091310
// At half-way past the minimum size, vanish the sidebar entirely
13101311
const SIDEBAR_VANISH_THRESHOLD = SIDEBAR_MIN / 2;
@@ -1474,6 +1475,9 @@ href="https://doc.rust-lang.org/${channel}/rustdoc/how-to-read-rustdoc.html\
14741475
}
14751476
// Respond to the window resize event.
14761477
window.addEventListener("resize", () => {
1478+
if (window.innerWidth < RUSTDOC_MOBILE_BREAKPOINT) {
1479+
return;
1480+
}
14771481
stopResize();
14781482
if (desiredSidebarSize >= (window.innerWidth - BODY_MIN)) {
14791483
changeSidebarSize(window.innerWidth - BODY_MIN);

tests/rustdoc-gui/sidebar-resize-window.goml

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ wait-for-property: (".sidebar", {"clientWidth": 500}, [NEAR])
1818
// make the window small enough that the sidebar has to shrink
1919
set-window-size: (750, 600)
2020
wait-for-property: (".sidebar", {"clientWidth": 350}, [NEAR])
21+
assert-local-storage: {"rustdoc-desktop-sidebar-width": "350"}
22+
set-window-size: (400, 600)
23+
wait-for-css: (".sidebar", {"display": "block", "left": "-1000px"})
24+
assert-local-storage: {"rustdoc-desktop-sidebar-width": "350"}
2125

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

0 commit comments

Comments
 (0)