Skip to content

Commit 267776a

Browse files
authored
Rollup merge of #93521 - jsha:sidebar-hover, r=GuillaumeGomez
Fix hover effects in sidebar The dark and ayu themes have a menu-like highlight on sidebar items. The light theme used to, but it was accidentally lost in the sidebar unification. The change brings back the hover effect in the light theme. It also makes the hover effect apply consistently to all links in the sidebar, including headings. It also simplifies the "In _path_" heading so it's one big link. The breadcrumbs are still readily available at the top of the page. Note that a small number of headings are not linkified and so don't get the hover effect. That will be fixed with #92957. Demo: https://rustdoc.crud.net/jsha/sidebar-hover/std/string/trait.ToString.html r? `@GuillaumeGomez` Fixes #93115
2 parents 6024426 + c20e2a9 commit 267776a

File tree

8 files changed

+23
-38
lines changed

8 files changed

+23
-38
lines changed

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

+7-12
Original file line numberDiff line numberDiff line change
@@ -463,9 +463,6 @@ nav.sub {
463463
.location a:first-of-type {
464464
font-weight: 500;
465465
}
466-
.location a:hover {
467-
text-decoration: underline;
468-
}
469466

470467
.block {
471468
padding: 0;
@@ -476,10 +473,11 @@ nav.sub {
476473
list-style: none;
477474
}
478475

479-
.block a {
476+
.block a,
477+
h2.location a {
480478
display: block;
481-
padding: 0.3em;
482-
margin-left: -0.3em;
479+
padding: 0.3rem;
480+
margin-left: -0.3rem;
483481

484482
text-overflow: ellipsis;
485483
overflow: hidden;
@@ -494,8 +492,8 @@ nav.sub {
494492
font-weight: 500;
495493
padding: 0;
496494
margin: 0;
497-
margin-top: 1rem;
498-
margin-bottom: 1rem;
495+
margin-top: 0.7rem;
496+
margin-bottom: 0.7rem;
499497
}
500498

501499
.sidebar h3 {
@@ -1812,10 +1810,7 @@ details.rustdoc-toggle[open] > summary.hideme::after {
18121810

18131811
.mobile-topbar .location {
18141812
border: none;
1815-
margin: 0;
1816-
margin-left: auto;
1817-
padding: 0.3em;
1818-
padding-right: 0.6em;
1813+
margin: auto 0.5em auto auto;
18191814
text-overflow: ellipsis;
18201815
overflow: hidden;
18211816
white-space: nowrap;

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

+6-10
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ pre, .rustdoc.source .example-wrap {
9191
background-color: #5c6773;
9292
}
9393

94-
.sidebar .current {
94+
.sidebar .current,
95+
.sidebar a:hover {
9596
background-color: transparent;
9697
color: #ffb44c;
9798
}
@@ -104,15 +105,6 @@ pre, .rustdoc.source .example-wrap {
104105
color: #ff7733;
105106
}
106107

107-
.sidebar-elems .location a {
108-
color: #fff;
109-
}
110-
111-
.block a:hover {
112-
background: transparent;
113-
color: #ffb44c;
114-
}
115-
116108
.line-numbers span { color: #5c6773; }
117109
.line-numbers .line-highlighted {
118110
color: #708090;
@@ -220,6 +212,10 @@ pre.rust a,
220212
.in-band a {
221213
color: #c5c5c5;
222214
}
215+
.sidebar h2 a,
216+
.sidebar h3 a {
217+
color: white;
218+
}
223219
.search-results a {
224220
color: #0096cf;
225221
}

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

+3-6
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,15 @@ pre, .rustdoc.source .example-wrap {
6161
background-color: rgba(32, 34, 37, .6);
6262
}
6363

64-
.sidebar .current {
65-
background-color: #333;
64+
.sidebar .current,
65+
.sidebar a:hover {
66+
background: #444;
6667
}
6768

6869
.source .sidebar {
6970
background-color: #565656;
7071
}
7172

72-
.block a:hover {
73-
background: #444;
74-
}
75-
7673
.line-numbers span { color: #3B91E2; }
7774
.line-numbers .line-highlighted {
7875
background-color: #0a042f !important;

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

+2-5
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,15 @@ pre, .rustdoc.source .example-wrap {
6363
background-color: rgba(36, 37, 39, 0.6);
6464
}
6565

66-
.sidebar .current {
66+
.sidebar .current,
67+
.sidebar a:hover {
6768
background-color: #fff;
6869
}
6970

7071
.source .sidebar {
7172
background-color: #f1f1f1;
7273
}
7374

74-
.block a:hover {
75-
background: #F5F5F5;
76-
}
77-
7875
.line-numbers span { color: #c67e2d; }
7976
.line-numbers .line-highlighted {
8077
background-color: #FDFFD3 !important;

src/test/rustdoc-gui/mobile.goml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ assert-css: (".main-heading", {
1111
"flex-direction": "column"
1212
})
1313

14-
assert-property: (".mobile-topbar h2.location", {"offsetHeight": 45})
14+
assert-property: (".mobile-topbar h2.location", {"offsetHeight": 48})
1515

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

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@ assert-position: ("#method\.must_use", {"y": 45})
3939
// Check that the bottom-most item on the sidebar menu can be scrolled fully into view.
4040
click: ".sidebar-menu-toggle"
4141
scroll-to: ".block.keyword li:nth-child(1)"
42-
assert-position: (".block.keyword li:nth-child(1)", {"y": 542.234375})
42+
compare-elements-position-near: (".block.keyword li:nth-child(1)", ".mobile-topbar", {"y": 543})

src/test/rustdoc-gui/sidebar.goml

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ assert-text: ("#functions + .item-table .item-left > a", "foo")
7777

7878
// Links to trait implementations in the sidebar should not wrap even if they are long.
7979
goto: file://|DOC_PATH|/lib2/struct.HasALongTraitWithParams.html
80-
assert-property: (".sidebar-links a", {"offsetHeight": 29})
80+
assert-property: (".sidebar-links a", {"offsetHeight": 30})
8181

8282
// Test that clicking on of the "In <module>" headings in the sidebar links to the
8383
// appropriate anchor in index.html.

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

+2-2
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-
assert-property: (".mobile-topbar .location", {"scrollWidth": "986"})
36-
assert-property: (".mobile-topbar .location", {"clientWidth": "504"})
35+
assert-property: (".mobile-topbar .location", {"scrollWidth": "493"})
36+
assert-property: (".mobile-topbar .location", {"clientWidth": "493"})
3737
assert-css: (".mobile-topbar .location", {"overflow-x": "hidden"})

0 commit comments

Comments
 (0)