about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Howell <michael@notriddle.com>2023-10-11 12:15:33 -0700
committerMichael Howell <michael@notriddle.com>2023-10-11 12:15:33 -0700
commitfd9f1a7148b47722d617bd896a8ead7211762d22 (patch)
tree6c61eac9ea9ae70c72c8935492fb1214277367d2
parent77fa09d9a1ddc7f99b0cda10c26688fe6f2b5519 (diff)
downloadrust-fd9f1a7148b47722d617bd896a8ead7211762d22.tar.gz
rust-fd9f1a7148b47722d617bd896a8ead7211762d22.zip
rustdoc: fix resize trouble with mobile
-rw-r--r--src/librustdoc/html/static/js/main.js4
-rw-r--r--tests/rustdoc-gui/sidebar-resize-window.goml4
2 files changed, 8 insertions, 0 deletions
diff --git a/src/librustdoc/html/static/js/main.js b/src/librustdoc/html/static/js/main.js
index be314317209..9ba5dc8a3a6 100644
--- a/src/librustdoc/html/static/js/main.js
+++ b/src/librustdoc/html/static/js/main.js
@@ -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;
@@ -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);
diff --git a/tests/rustdoc-gui/sidebar-resize-window.goml b/tests/rustdoc-gui/sidebar-resize-window.goml
index 04321acc105..fb6baafda71 100644
--- a/tests/rustdoc-gui/sidebar-resize-window.goml
+++ b/tests/rustdoc-gui/sidebar-resize-window.goml
@@ -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)