Skip to content

Commit a998a37

Browse files
committed
rustdoc: small fixes to mobile navigation
- Make sure the mobile-topbar doesn't overflow its height if the user sets a bigger font. - Make sure the sidebar can be scrolled all the way to the bottom by shortening it to accommodate the mobile-topbar. - Make the item name in the mobile-topbar clickable to go to the top of the page. - Remove excess padding sidebar in mobile mode.
1 parent a00e130 commit a998a37

File tree

8 files changed

+26
-4
lines changed

8 files changed

+26
-4
lines changed

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

+12-2
Original file line numberDiff line numberDiff line change
@@ -1799,8 +1799,9 @@ details.rustdoc-toggle[open] > summary.hideme::after {
17991799
background-color: rgba(0,0,0,0);
18001800
margin: 0;
18011801
padding: 0;
1802-
padding-left: 15px;
18031802
z-index: 11;
1803+
/* Reduce height slightly to account for mobile topbar. */
1804+
height: calc(100vh - 45px);
18041805
}
18051806

18061807
/* The source view uses a different design for the sidebar toggle, and doesn't have a topbar,
@@ -1831,7 +1832,13 @@ details.rustdoc-toggle[open] > summary.hideme::after {
18311832
padding: 0.3em;
18321833
padding-right: 0.6em;
18331834
text-overflow: ellipsis;
1834-
overflow-x: hidden;
1835+
overflow: hidden;
1836+
white-space: nowrap;
1837+
/* Rare exception to specifying font sizes in rem. Since the topbar
1838+
height is specified in pixels, this also has to be specified in
1839+
pixels to avoid overflowing the topbar when the user sets a bigger
1840+
font size. */
1841+
font-size: 22.4px;
18351842
}
18361843

18371844
.mobile-topbar .logo-container {
@@ -1864,6 +1871,9 @@ details.rustdoc-toggle[open] > summary.hideme::after {
18641871

18651872
.sidebar-menu-toggle {
18661873
width: 45px;
1874+
/* Rare exception to specifying font sizes in rem. Since this is acting
1875+
as an icon, it's okay to specify its sizes in pixels. */
1876+
font-size: 32px;
18671877
border: none;
18681878
}
18691879

src/librustdoc/html/static/css/themes/ayu.css

+1
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ a.anchor,
216216
pre.rust a,
217217
.sidebar h2 a,
218218
.sidebar h3 a,
219+
.mobile-topbar h2 a,
219220
.in-band a {
220221
color: #c5c5c5;
221222
}

src/librustdoc/html/static/css/themes/dark.css

+1
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ a.anchor,
192192
pre.rust a,
193193
.sidebar h2 a,
194194
.sidebar h3 a,
195+
.mobile-topbar h2 a,
195196
.in-band a {
196197
color: #ddd;
197198
}

src/librustdoc/html/static/css/themes/light.css

+1
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ a.anchor,
189189
pre.rust a,
190190
.sidebar h2 a,
191191
.sidebar h3 a,
192+
.mobile-topbar h2 a,
192193
.in-band a {
193194
color: #000;
194195
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function resourcePath(basename, extension) {
7272
var mobileLocationTitle = document.querySelector(".mobile-topbar h2.location");
7373
var locationTitle = document.querySelector(".sidebar h2.location");
7474
if (mobileLocationTitle && locationTitle) {
75-
mobileLocationTitle.innerText = locationTitle.innerText;
75+
mobileLocationTitle.innerHTML = locationTitle.innerHTML;
7676
}
7777
}
7878
}());

src/test/rustdoc-gui/mobile.goml

+4
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@
22
goto: file://|DOC_PATH|/staged_api/struct.Foo.html
33
size: (400, 600)
44

5+
font-size: 18
6+
57
// The out-of-band info (source, stable version, collapse) should be below the
68
// h1 when the screen gets narrow enough.
79
assert-css: (".main-heading", {
810
"display": "flex",
911
"flex-direction": "column"
1012
})
1113

14+
assert-property: (".mobile-topbar h2.location", {"offsetHeight": 45})
15+
1216
// Note: We can't use assert-text here because the 'Since' is set by CSS and
1317
// is therefore not part of the DOM.
1418
assert-css: (".content .out-of-band .since::before", { "content": "\"Since \"" })

src/test/rustdoc-gui/sidebar-mobile.goml

+5
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,8 @@ assert-property: (".mobile-topbar", {"clientHeight": "45"})
3535
click: ".sidebar-menu-toggle"
3636
click: ".sidebar-links a"
3737
assert-position: ("#method\.must_use", {"y": 45})
38+
39+
// Check that the bottom-most item on the sidebar menu can be scrolled fully into view.
40+
click: ".sidebar-menu-toggle"
41+
scroll-to: ".block.keyword li:nth-child(1)"
42+
assert-position: (".block.keyword li:nth-child(1)", {"y": 542.96875})

src/test/rustdoc-gui/type-declation-overflow.goml

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ assert-property: (".item-decl pre", {"scrollWidth": "950"})
3131
// On mobile:
3232
size: (600, 600)
3333
goto: file://|DOC_PATH|/lib2/too_long/struct.SuperIncrediblyLongLongLongLongLongLongLongGigaGigaGigaMegaLongLongLongStructName.html
34-
assert-property: (".mobile-topbar .location", {"scrollWidth": "504"})
34+
assert-property: (".mobile-topbar .location", {"scrollWidth": "986"})
3535
assert-property: (".mobile-topbar .location", {"clientWidth": "504"})
3636
assert-css: (".mobile-topbar .location", {"overflow-x": "hidden"})

0 commit comments

Comments
 (0)