Skip to content

Commit 7455076

Browse files
authored
Unrolled build for #151216
Rollup merge of #151216 - scrollable-popover-content, r=lolbinarycat [rustdoc] Make popover menus content scrollable on mobile devices Fixes #151209. This is what it looks like: <img width="468" height="601" alt="image" src="https://github.com/user-attachments/assets/39dcbfea-ca31-4875-947f-155b58ffa4bd" /> The only difference with the current display: <img width="468" height="601" alt="image" src="https://github.com/user-attachments/assets/b49c6100-3566-4f79-8343-1bf4fe32da78" /> is that we now see the bottom border (and that we can scroll the content too of course). I applied this change to both the settings and helps popover menus. r? @lolbinarycat
2 parents 5c49c4f + d5bacdd commit 7455076

File tree

3 files changed

+61
-11
lines changed

3 files changed

+61
-11
lines changed

src/librustdoc/html/static/css/rustdoc.css

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
--src-sidebar-width: 300px;
2121
--desktop-sidebar-z-index: 100;
2222
--sidebar-elems-left-padding: 24px;
23+
--popover-top-margin: 7px;
2324
/* clipboard <https://github.com/rust-lang/crates.io/commits/main/public/assets/copy.svg> */
2425
--clipboard-image: url('data:image/svg+xml,<svg width="19" height="18" viewBox="0 0 24 25" \
2526
xmlns="http://www.w3.org/2000/svg" aria-label="Copy to clipboard">\
@@ -1435,7 +1436,7 @@ so that we can apply CSS-filters to change the arrow color in themes */
14351436
top: 100%;
14361437
right: 0;
14371438
z-index: calc(var(--desktop-sidebar-z-index) + 1);
1438-
margin-top: 7px;
1439+
margin-top: var(--popover-top-margin);
14391440
border-radius: 3px;
14401441
border: 1px solid var(--border-color);
14411442
background-color: var(--main-background-color);
@@ -2659,14 +2660,15 @@ in src-script.js and main.js
26592660
@media (max-width: 700px) {
26602661
:root {
26612662
--impl-items-indent: 0.7em;
2663+
--topbar-height: 45px;
26622664
}
26632665

26642666
/* When linking to an item with an `id` (for instance, by clicking a link in the sidebar,
26652667
or visiting a URL with a fragment like `#method.new`, we don't want the item to be obscured
26662668
by the topbar. Anything with an `id` gets scroll-margin-top equal to rustdoc-topbar's size.
26672669
*/
26682670
*[id] {
2669-
scroll-margin-top: 45px;
2671+
scroll-margin-top: var(--topbar-height);
26702672
}
26712673

26722674
/* We don't display this button on mobile devices. */
@@ -2698,14 +2700,23 @@ in src-script.js and main.js
26982700
background: var(--main-background-color);
26992701
border-radius: 0;
27002702
}
2701-
#settings.popover {
2703+
#settings.popover, #help.popover {
27022704
top: 32px;
2705+
/* The `+ 1px` part is for the bottom border to be visible. */
2706+
height: calc(100vh - var(--topbar-height) + var(--popover-top-margin) - 1px);
2707+
}
2708+
#settings.popover {
27032709
--popover-arrow-offset: 48px;
27042710
}
27052711
#help.popover {
2706-
top: 32px;
27072712
--popover-arrow-offset: 12px;
27082713
}
2714+
/* The `overflow-y` property is used on an internal content instead of the top one otherwise the
2715+
little arrow at the top can't be displayed. */
2716+
#settings.popover .settings, #help.popover .content {
2717+
overflow-y: scroll;
2718+
height: 100%;
2719+
}
27092720

27102721
.rustdoc {
27112722
/* Sidebar should overlay main content, rather than pushing main content to the right.
@@ -2728,13 +2739,13 @@ in src-script.js and main.js
27282739

27292740
.sidebar {
27302741
position: fixed;
2731-
top: 45px;
2742+
top: var(--topbar-height);
27322743
/* Hide the sidebar offscreen while not in use. Doing this instead of display: none means
27332744
the sidebar stays visible for screen readers, which is useful for navigation. */
27342745
left: -1000px;
27352746
z-index: 11;
27362747
/* Reduce height slightly to account for mobile topbar. */
2737-
height: calc(100vh - 45px);
2748+
height: calc(100vh - var(--topbar-height));
27382749
/* resize indicator: hide this when on touch or mobile */
27392750
border-right: none;
27402751
width: 100%;
@@ -2799,7 +2810,7 @@ in src-script.js and main.js
27992810
flex-direction: row;
28002811
position: sticky;
28012812
z-index: 10;
2802-
height: 45px;
2813+
height: var(--topbar-height);
28032814
width: 100%;
28042815
left: 0;
28052816
top: 0;

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1692,7 +1692,7 @@ function preLoadCss(cssUrl) {
16921692

16931693
const container = document.createElement("div");
16941694
if (!isHelpPage) {
1695-
container.className = "popover content";
1695+
container.className = "popover";
16961696
}
16971697
container.id = "help";
16981698

@@ -1701,9 +1701,14 @@ function preLoadCss(cssUrl) {
17011701
side_by_side.appendChild(div_shortcuts);
17021702
side_by_side.appendChild(div_infos);
17031703

1704-
container.appendChild(book_info);
1705-
container.appendChild(side_by_side);
1706-
container.appendChild(rustdoc_version);
1704+
const content = document.createElement("div");
1705+
content.className = "content";
1706+
1707+
content.appendChild(book_info);
1708+
content.appendChild(side_by_side);
1709+
content.appendChild(rustdoc_version);
1710+
1711+
container.appendChild(content);
17071712

17081713
if (isHelpPage) {
17091714
const help_section = document.createElement("section");
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Ensure that topbar popover menus content can be scrolled on mobile.
2+
go-to: "file://" + |DOC_PATH| + "/lib2/index.html"
3+
store-value: (window_height, 500)
4+
set-window-size: (400, |window_height|)
5+
6+
include: "utils.goml"
7+
8+
// We open the settings menu
9+
call-function: ("open-settings-menu", {})
10+
// We ensure it's not scrolled down yet.
11+
assert-property: ("#settings .settings", {"scrollTop": 0})
12+
// We ensure its height is smaller than the window's, but its content's height is bigger.
13+
store-property: ("#settings .settings", {"offsetHeight": menu_height, "scrollHeight": scroll_height})
14+
assert: |menu_height| < |window_height| && |scroll_height| > |window_height|
15+
16+
// We scroll to the last element of the menu.
17+
scroll-to: "#settings .setting-line:last-of-type input"
18+
// The item should be visible now, and so the Y scroll value should have changed.
19+
// Note: The `scrollTop` value will change if settings are added or removed.
20+
assert-property: ("#settings .settings", {"scrollTop": 335})
21+
22+
// Now we open the help menu.
23+
click: ".help-menu a"
24+
wait-for: "#help"
25+
// We ensure it's not scrolled down yet.
26+
assert-property: ("#help .content", {"scrollTop": 0})
27+
// We ensure its height is smaller than the window's, but its content's height is bigger.
28+
store-property: ("#help .content", {"offsetHeight": menu_height, "scrollHeight": scroll_height})
29+
assert: |menu_height| < |window_height| && |scroll_height| > |window_height|
30+
31+
// We scroll to the last element of the menu.
32+
scroll-to: "#help .infos > :last-child"
33+
// The item should be visible now, and so the Y scroll value should have changed.
34+
assert-property: ("#help .content", {"scrollTop": 339})

0 commit comments

Comments
 (0)