From fd9f1a7148b47722d617bd896a8ead7211762d22 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Wed, 11 Oct 2023 12:15:33 -0700 Subject: [PATCH] rustdoc: fix resize trouble with mobile --- src/librustdoc/html/static/js/main.js | 4 ++++ tests/rustdoc-gui/sidebar-resize-window.goml | 4 ++++ 2 files changed, 8 insertions(+) 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)