rustdoc: use CSS overscroll-behavior
instead of JavaScript
Fixes the desktop scrolling weirdness mentioned in https://github.com/rust-lang/rust/pull/98775#issuecomment-1182575603 As described in the MDN page for this property: * The current Firefox ESR is 102, and the first Firefox version to support this feature is 59. * The current Chrome version 112, and the first version to support this is 63. * Edge is described as having a minor bug in `none` mode, but we use `contain` mode anyway, so it doesn't matter. * Safari 16, released September 2022, is the last browser to add this feature, and is also the oldest version we officially support.
This commit is contained in:
parent
661b33f524
commit
bb7ed64f45
5 changed files with 19 additions and 96 deletions
|
@ -1,31 +1,12 @@
|
|||
// This test ensures that the mobile sidebar preserves scroll position.
|
||||
// This test ensures that the mobile disables scrolling the page.
|
||||
go-to: "file://" + |DOC_PATH| + "/test_docs/struct.Foo.html"
|
||||
// Switching to "mobile view" by reducing the width to 600px.
|
||||
set-window-size: (700, 600)
|
||||
assert-css: (".sidebar", {"display": "block", "left": "-1000px"})
|
||||
set-window-size: (1280, 800) // desktop
|
||||
assert-css: (".sidebar", {"overscroll-behavior": "contain"})
|
||||
set-window-size: (700, 600) // mobile
|
||||
assert-css: (".sidebar", {"overscroll-behavior": "contain"})
|
||||
|
||||
// Scroll down.
|
||||
scroll-to: "//h2[@id='blanket-implementations']"
|
||||
assert-window-property: {"pageYOffset": "622"}
|
||||
|
||||
// Open the sidebar menu.
|
||||
click: ".sidebar-menu-toggle"
|
||||
wait-for-css: (".sidebar", {"left": "0px"})
|
||||
|
||||
// We are no longer "scrolled". It's important that the user can't
|
||||
// scroll the body at all, but these test scripts are run only in Chrome,
|
||||
// and we need to use a more complicated solution to this problem because
|
||||
// of Mobile Safari...
|
||||
assert-window-property: {"pageYOffset": "0"}
|
||||
|
||||
// Close the sidebar menu. Make sure the scroll position gets restored.
|
||||
click: ".sidebar-menu-toggle"
|
||||
wait-for-css: (".sidebar", {"left": "-1000px"})
|
||||
assert-window-property: {"pageYOffset": "622"}
|
||||
|
||||
// Now test that scrollability returns when the browser window is just resized.
|
||||
click: ".sidebar-menu-toggle"
|
||||
wait-for-css: (".sidebar", {"left": "0px"})
|
||||
assert-window-property: {"pageYOffset": "0"}
|
||||
set-window-size: (900, 600)
|
||||
assert-window-property: {"pageYOffset": "622"}
|
||||
go-to: "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html"
|
||||
set-window-size: (1280, 800) // desktop
|
||||
assert-css: (".sidebar", {"overscroll-behavior": "contain"})
|
||||
set-window-size: (700, 600) // mobile
|
||||
assert-css: (".sidebar", {"overscroll-behavior": "contain"})
|
||||
|
|
|
@ -183,22 +183,12 @@ wait-for-css: (".sidebar", {"left": "-1000px"})
|
|||
// The "scrollTop" property should be the same.
|
||||
assert-window-property: {"pageYOffset": "2542"}
|
||||
|
||||
// We now check that the scroll position is restored if the window is resized.
|
||||
set-window-size: (500, 700)
|
||||
click: "#src-sidebar-toggle"
|
||||
wait-for-css: ("#source-sidebar", {"visibility": "visible"})
|
||||
assert-window-property: {"pageYOffset": "0"}
|
||||
set-window-size: (900, 900)
|
||||
assert-window-property: {"pageYOffset": "2542"}
|
||||
set-window-size: (500, 700)
|
||||
click: "#src-sidebar-toggle"
|
||||
wait-for-css: ("#source-sidebar", {"visibility": "hidden"})
|
||||
|
||||
// We now check that opening the sidebar and clicking a link will close it.
|
||||
// The behavior here on mobile is different than the behavior on desktop,
|
||||
// but common sense dictates that if you have a list of files that fills the entire screen, and
|
||||
// you click one of them, you probably want to actually see the file's contents, and not just
|
||||
// make it the current selection.
|
||||
set-window-size: (500, 700)
|
||||
click: "#src-sidebar-toggle"
|
||||
wait-for-css: ("#source-sidebar", {"visibility": "visible"})
|
||||
assert-local-storage: {"rustdoc-source-sidebar-show": "true"}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue