Skip to content

Commit a01b885

Browse files
committed
rustdoc: remove class name location from sidebar sibling nav
This change tweaks the CSS to apply most of its styles to `.sidebar h2`, cleaning up a few redundant rules from `.mobile-topbar .location` and restoring useful navigation aids in mobile mode.
1 parent e94827e commit a01b885

File tree

8 files changed

+39
-38
lines changed

8 files changed

+39
-38
lines changed

src/librustdoc/html/render/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1884,7 +1884,7 @@ fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut Buffer) {
18841884
if !it.is_mod() {
18851885
let path: String = cx.current.iter().map(|s| s.as_str()).intersperse("::").collect();
18861886

1887-
write!(buffer, "<h2 class=\"location\"><a href=\"index.html\">In {}</a></h2>", path);
1887+
write!(buffer, "<h2><a href=\"index.html\">In {}</a></h2>", path);
18881888
}
18891889

18901890
// Closes sidebar-elems div.

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

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ h1.fqn {
171171
Rustdoc-generated h2 section headings (e.g. "Implementations", "Required Methods", etc)
172172
Underlines elsewhere in the documentation break up visual flow and tend to invert
173173
section hierarchies. */
174-
h2,
174+
.content h2,
175175
.top-doc .docblock > h3,
176176
.top-doc .docblock > h4 {
177177
border-bottom: 1px solid var(--headings-border-bottom-color);
@@ -397,15 +397,6 @@ img {
397397
left: 0;
398398
}
399399

400-
.sidebar-elems,
401-
.sidebar > .location {
402-
padding-left: 24px;
403-
}
404-
405-
.sidebar .location {
406-
overflow-wrap: anywhere;
407-
}
408-
409400
.rustdoc.source .sidebar {
410401
width: 50px;
411402
min-width: 0px;
@@ -504,8 +495,8 @@ ul.block, .block li {
504495
}
505496

506497
.block a,
507-
.sidebar h3 a,
508-
h2.location a {
498+
.sidebar h2 a,
499+
.sidebar h3 a {
509500
display: block;
510501
padding: 0.25rem;
511502
margin-left: -0.25rem;
@@ -515,8 +506,7 @@ h2.location a {
515506
}
516507

517508
.sidebar h2 {
518-
border-bottom: none;
519-
font-weight: 500;
509+
overflow-wrap: anywhere;
520510
padding: 0;
521511
margin: 0;
522512
margin-top: 0.7rem;
@@ -525,11 +515,15 @@ h2.location a {
525515

526516
.sidebar h3 {
527517
font-size: 1.125rem; /* 18px */
528-
font-weight: 500;
529518
padding: 0;
530519
margin: 0;
531520
}
532521

522+
.sidebar-elems,
523+
.sidebar > h2 {
524+
padding-left: 24px;
525+
}
526+
533527
.sidebar a, .sidebar .current {
534528
color: var(--sidebar-link-color);
535529
}
@@ -1798,25 +1792,24 @@ in storage.js plus the media query with (min-width: 701px)
17981792
width: 0;
17991793
}
18001794

1801-
.mobile-topbar .location a {
1802-
padding: 0;
1803-
margin: 0;
1804-
}
1805-
1806-
.mobile-topbar .location {
1807-
border: none;
1808-
padding: 0;
1795+
.mobile-topbar h2 {
1796+
padding-bottom: 0;
18091797
margin: auto 0.5em auto auto;
1810-
text-overflow: ellipsis;
18111798
overflow: hidden;
1812-
white-space: nowrap;
18131799
/* Rare exception to specifying font sizes in rem. Since the topbar
18141800
height is specified in pixels, this also has to be specified in
18151801
pixels to avoid overflowing the topbar when the user sets a bigger
18161802
font size. */
18171803
font-size: 24px;
18181804
}
18191805

1806+
.mobile-topbar h2 a {
1807+
display: block;
1808+
text-overflow: ellipsis;
1809+
overflow: hidden;
1810+
white-space: nowrap;
1811+
}
1812+
18201813
.mobile-topbar .logo-container {
18211814
max-height: 45px;
18221815
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function blurHandler(event, parentElem, hideCallback) {
5555
function setMobileTopbar() {
5656
// FIXME: It would be nicer to generate this text content directly in HTML,
5757
// but with the current code it's hard to get the right information in the right place.
58-
const mobileLocationTitle = document.querySelector(".mobile-topbar h2.location");
58+
const mobileLocationTitle = document.querySelector(".mobile-topbar h2");
5959
const locationTitle = document.querySelector(".sidebar h2.location");
6060
if (mobileLocationTitle && locationTitle) {
6161
mobileLocationTitle.innerHTML = locationTitle.innerHTML;

src/librustdoc/html/templates/page.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
{%- endif -%}
8686
</div> {#- -#}
8787
</a> {#- -#}
88-
<h2 class="location"></h2> {#- -#}
88+
<h2></h2> {#- -#}
8989
</nav> {#- -#}
9090
{%- endif -%}
9191
<nav class="sidebar"> {#- -#}

src/test/rustdoc-gui/mobile.goml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ assert-css: (".main-heading", {
1212
"flex-direction": "column"
1313
})
1414

15-
assert-property: (".mobile-topbar h2.location", {"offsetHeight": 36})
15+
assert-property: (".mobile-topbar h2", {"offsetHeight": 36})
1616

1717
// Note: We can't use assert-text here because the 'Since' is set by CSS and
1818
// is therefore not part of the DOM.

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ assert-css: (".sidebar", {"display": "block", "left": "-1000px"})
2323
click: ".sidebar-menu-toggle"
2424
assert-css: (".sidebar", {"left": "0px"})
2525

26+
// Make sure the "struct Foo" header is hidden, since the mobile topbar already does it.
27+
assert-css: ("//nav[contains(@class, 'sidebar')]//h2/a[text()='Foo']/parent::h2", {"display": "none"})
28+
// Make sure the global navigation is still here.
29+
assert-css: ("//nav[contains(@class, 'sidebar')]//h2/a[text()='In test_docs']/parent::h2", {"display": "block"})
30+
2631
// Click elsewhere.
2732
click: "body"
2833
assert-css: (".sidebar", {"display": "block", "left": "-1000px"})
@@ -39,7 +44,7 @@ assert-position: ("#method\.must_use", {"y": 45})
3944
// Check that the bottom-most item on the sidebar menu can be scrolled fully into view.
4045
click: ".sidebar-menu-toggle"
4146
scroll-to: ".block.keyword li:nth-child(1)"
42-
compare-elements-position-near: (".block.keyword li:nth-child(1)", ".mobile-topbar", {"y": 543})
47+
compare-elements-position-near: (".block.keyword li:nth-child(1)", ".mobile-topbar", {"y": 543.19})
4348

4449
// Now checking the background color of the sidebar.
4550
show-text: true

src/test/rustdoc-gui/sidebar.goml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ reload:
99
assert-text: (".sidebar > .location", "Crate test_docs")
1010
// In modules, we only have one "location" element.
1111
assert-count: (".sidebar .location", 1)
12+
assert-count: (".sidebar h2", 1)
1213
assert-text: ("#all-types", "All Items")
1314
assert-css: ("#all-types", {"color": "rgb(53, 109, 164)"})
1415
// We check that we have the crates list and that the "current" on is "test_docs".
@@ -28,7 +29,8 @@ assert-text: ("#structs + .item-table .item-left > a", "Foo")
2829
click: "#structs + .item-table .item-left > a"
2930

3031
// PAGE: struct.Foo.html
31-
assert-count: (".sidebar .location", 2)
32+
assert-count: (".sidebar .location", 1)
33+
assert-count: (".sidebar h2", 2)
3234
// We check that there is no crate listed outside of the top level.
3335
assert-false: ".sidebar-elems > .crate"
3436

@@ -60,10 +62,11 @@ assert-text: ("#functions + .item-table .item-left > a", "foobar")
6062
click: "#functions + .item-table .item-left > a"
6163

6264
// PAGE: fn.foobar.html
63-
// In items containing no items (like functions or constants) and in modules, we have one
64-
// "location" elements.
65-
assert-count: (".sidebar .location", 1)
66-
assert-text: (".sidebar .sidebar-elems .location", "In lib2")
65+
// In items containing no items (like functions or constants) and in modules, we have no
66+
// "location" elements. Only the parent module h2.
67+
assert-count: (".sidebar .location", 0)
68+
assert-count: (".sidebar h2", 1)
69+
assert-text: (".sidebar .sidebar-elems h2", "In lib2")
6770
// We check that we don't have the crate list.
6871
assert-false: ".sidebar-elems > .crate"
6972

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@ assert-property: (".item-decl pre", {"scrollWidth": "950"})
3232
size: (600, 600)
3333
goto: "file://" + |DOC_PATH| + "/lib2/too_long/struct.SuperIncrediblyLongLongLongLongLongLongLongGigaGigaGigaMegaLongLongLongStructName.html"
3434
// It shouldn't have an overflow in the topbar either.
35-
store-property: (scrollWidth, ".mobile-topbar .location", "scrollWidth")
36-
assert-property: (".mobile-topbar .location", {"clientWidth": |scrollWidth|})
37-
assert-css: (".mobile-topbar .location", {"overflow-x": "hidden"})
35+
store-property: (scrollWidth, ".mobile-topbar h2", "scrollWidth")
36+
assert-property: (".mobile-topbar h2", {"clientWidth": |scrollWidth|})
37+
assert-css: (".mobile-topbar h2", {"overflow-x": "hidden"})

0 commit comments

Comments
 (0)