Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustdoc: remove CSS @media (min-width: 701px) #103164

Merged
merged 2 commits into from
Oct 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 10 additions & 20 deletions src/librustdoc/html/static/css/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ img {

.source-sidebar-expanded .source .sidebar {
overflow-y: auto;
width: 300px;
}

.source-sidebar-expanded .source .sidebar > *:not(#sidebar-toggle) {
Expand Down Expand Up @@ -1692,31 +1693,20 @@ details.rustdoc-toggle[open] > summary.hideme::after {
display: inline-block;
}

/* Media Queries */

/*
WARNING: RUSTDOC_MOBILE_BREAKPOINT MEDIA QUERY;
If you update this line, then you also need to update the line with the same warning
in storage.js plus the media query with (max-width: 700px)
*/
@media (min-width: 701px) {
/* In case there is no documentation before a code block, we need to add some margin at the top
to prevent an overlay between the "collapse toggle" and the information tooltip.
However, it's not needed with smaller screen width because the doc/code block is always put
"one line" below. */
.docblock > .example-wrap:first-child .tooltip {
margin-top: 16px;
}

.source-sidebar-expanded .source .sidebar {
width: 300px;
}
/* In case there is no documentation before a code block, we need to add some margin at the top
to prevent an overlay between the "collapse toggle" and the information tooltip.
However, it's not needed with smaller screen width because the doc/code block is always put
"one line" below. */
.docblock > .example-wrap:first-child .tooltip {
margin-top: 16px;
}

/* Media Queries */

/*
WARNING: RUSTDOC_MOBILE_BREAKPOINT MEDIA QUERY
If you update this line, then you also need to update the line with the same warning
in storage.js plus the media query with (min-width: 701px)
in storage.js
*/
@media (max-width: 700px) {
/* When linking to an item with an `id` (for instance, by clicking a link in the sidebar,
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/html/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ function loadCss(cssFileName) {

window.rustdocMobileScrollLock = function() {
const mobile_topbar = document.querySelector(".mobile-topbar");
if (window.innerWidth < window.RUSTDOC_MOBILE_BREAKPOINT) {
if (window.innerWidth <= window.RUSTDOC_MOBILE_BREAKPOINT) {
// This is to keep the scroll position on mobile.
oldSidebarScrollPosition = window.scrollY;
document.body.style.width = `${document.body.offsetWidth}px`;
Expand Down Expand Up @@ -783,7 +783,7 @@ function loadCss(cssFileName) {
}

window.addEventListener("resize", () => {
if (window.innerWidth >= window.RUSTDOC_MOBILE_BREAKPOINT &&
if (window.innerWidth > window.RUSTDOC_MOBILE_BREAKPOINT &&
oldSidebarScrollPosition !== null) {
// If the user opens the sidebar in "mobile" mode, and then grows the browser window,
// we need to switch away from mobile mode and make the main content area scrollable.
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/html/static/js/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ window.currentTheme = document.getElementById("themeStyle");
window.mainTheme = document.getElementById("mainThemeStyle");

// WARNING: RUSTDOC_MOBILE_BREAKPOINT MEDIA QUERY
// If you update this line, then you also need to update the two media queries with the same
// If you update this line, then you also need to update the media query with the same
// warning in rustdoc.css
window.RUSTDOC_MOBILE_BREAKPOINT = 701;
window.RUSTDOC_MOBILE_BREAKPOINT = 700;

const settingsDataset = (function() {
const settingsElement = document.getElementById("default-settings");
Expand Down
8 changes: 4 additions & 4 deletions src/test/rustdoc-gui/sidebar-mobile-scroll.goml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// This test ensures that the mobile sidebar preserves scroll position.
goto: "file://" + |DOC_PATH| + "/test_docs/struct.Foo.html"
// Switching to "mobile view" by reducing the width to 600px.
size: (600, 600)
size: (700, 600)
assert-css: (".sidebar", {"display": "block", "left": "-1000px"})

// Scroll down.
scroll-to: "//h2[@id='blanket-implementations']"
assert-window-property: {"pageYOffset": "651"}
assert-window-property: {"pageYOffset": "627"}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would benefit from a store-window-property command.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can add one. :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


// Open the sidebar menu.
click: ".sidebar-menu-toggle"
Expand All @@ -21,11 +21,11 @@ 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": "651"}
assert-window-property: {"pageYOffset": "627"}

// 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"}
size: (900, 600)
assert-window-property: {"pageYOffset": "651"}
assert-window-property: {"pageYOffset": "627"}