Skip to content

Commit 9a4fe30

Browse files
authored
Rollup merge of #102146 - notriddle:notriddle/sidebar-jank, r=GuillaumeGomez
rustdoc: CSS prevent sidebar width change jank This commit makes the `width` and `min-width` of the sidebar the same. They originally were when cad0fce added the `min-width` rule, but 6a5f8b1 changed the `width` without changing the `min-width`, causing it to sometimes oscilate between 200 and 250 pixels depending on the main content. # Before [Screencast from 09-22-2022 10:25:29 AM.webm](https://user-images.githubusercontent.com/1593513/191813469-ea00f30f-6f49-40fc-9a26-e1dfd5068d2b.webm) # After [Screencast from 09-22-2022 10:32:20 AM.webm](https://user-images.githubusercontent.com/1593513/191813642-ae0902da-5262-403a-bbdf-995334201acb.webm)
2 parents 6b67b0d + cd48154 commit 9a4fe30

9 files changed

+28
-13
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ img {
411411

412412
.sidebar {
413413
font-size: 0.875rem;
414-
width: 250px;
414+
width: 200px;
415415
min-width: 200px;
416416
overflow-y: scroll;
417417
position: sticky;

src/test/rustdoc-gui/code-blocks-overflow.goml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ size: (1080, 600)
55
assert-count: (".docblock > .example-wrap", 2)
66
assert: ".docblock > .example-wrap > .language-txt"
77
assert: ".docblock > .example-wrap > .rust-example-rendered"
8-
assert-css: (".docblock > .example-wrap > pre", {"width": "785.25px", "overflow-x": "auto"}, ALL)
8+
assert-css: (".docblock > .example-wrap > pre", {"width": "796px", "overflow-x": "auto"}, ALL)

src/test/rustdoc-gui/docblock-table-overflow.goml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ goto: file://|DOC_PATH|/lib2/long_table/struct.Foo.html
44
size: (1100, 800)
55
// Logically, the ".docblock" and the "<p>" should have the same scroll width.
66
compare-elements-property: (".top-doc .docblock", ".top-doc .docblock > p", ["scrollWidth"])
7-
assert-property: (".top-doc .docblock", {"scrollWidth": "801"})
7+
assert-property: (".top-doc .docblock", {"scrollWidth": "816"})
88
// However, since there is overflow in the <table>, its scroll width is bigger.
99
assert-property: (".top-doc .docblock table", {"scrollWidth": "1572"})
1010

@@ -16,6 +16,6 @@ compare-elements-property: (
1616
"#implementations-list > details .docblock > p",
1717
["scrollWidth"],
1818
)
19-
assert-property: ("#implementations-list > details .docblock", {"scrollWidth": "801"})
19+
assert-property: ("#implementations-list > details .docblock", {"scrollWidth": "816"})
2020
// However, since there is overflow in the <table>, its scroll width is bigger.
2121
assert-property: ("#implementations-list > details .docblock table", {"scrollWidth": "1572"})

src/test/rustdoc-gui/item-info-overflow.goml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ goto: file://|DOC_PATH|/lib2/struct.LongItemInfo.html
44
size: (1200, 870)
55
// Logically, the "item-decl" and the "item-info" should have the same scroll width.
66
compare-elements-property: (".item-decl", ".item-info", ["scrollWidth"])
7-
assert-property: (".item-info", {"scrollWidth": "890"})
7+
assert-property: (".item-info", {"scrollWidth": "940"})
88
// Just to be sure we're comparing the correct "item-info":
99
assert-text: (
1010
".item-info",
@@ -21,7 +21,7 @@ compare-elements-property: (
2121
)
2222
assert-property: (
2323
"#impl-SimpleTrait-for-LongItemInfo2 .item-info",
24-
{"scrollWidth": "866"},
24+
{"scrollWidth": "916"},
2525
)
2626
// Just to be sure we're comparing the correct "item-info":
2727
assert-text: (

src/test/rustdoc-gui/item-info.goml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ goto: file://|DOC_PATH|/lib2/struct.Foo.html
44
// We set a fixed size so there is no chance of "random" resize.
55
size: (1100, 800)
66
// We check that ".item-info" is bigger than its content.
7-
assert-css: (".item-info", {"width": "790px"})
7+
assert-css: (".item-info", {"width": "840px"})
88
assert-css: (".item-info .stab", {"width": "289px"})
9-
assert-position: (".item-info .stab", {"x": 295})
9+
assert-position: (".item-info .stab", {"x": 245})
1010

1111
// Now we ensure that they're not rendered on the same line.
1212
goto: file://|DOC_PATH|/lib2/trait.Trait.html

src/test/rustdoc-gui/notable-trait.goml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ compare-elements-position-false: (
1818
// The `i` should be *after* the type.
1919
assert-position: (
2020
"//*[@id='method.create_an_iterator_from_read']//a[text()='NotableStructWithLongName']",
21-
{"x": 692},
21+
{"x": 677},
2222
)
2323
assert-position: (
2424
"//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']",
25-
{"x": 966},
25+
{"x": 951},
2626
)
2727

2828

src/test/rustdoc-gui/search-result-display.goml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ press-key: 'Enter'
77
wait-for: "#crate-search"
88
// The width is returned by "getComputedStyle" which returns the exact number instead of the
99
// CSS rule which is "50%"...
10-
assert-css: (".search-results div.desc", {"width": "293px"})
10+
assert-css: (".search-results div.desc", {"width": "318px"})
1111
size: (600, 100)
1212
// As counter-intuitive as it may seem, in this width, the width is "100%", which is why
1313
// when computed it's larger.

src/test/rustdoc-gui/sidebar.goml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Checks multiple things on the sidebar display (width of its elements, colors, etc).
22
goto: file://|DOC_PATH|/test_docs/index.html
3+
assert-property: (".sidebar", {"clientWidth": "200"})
34
show-text: true
45
local-storage: {"rustdoc-theme": "light"}
56
// We reload the page so the local storage settings are being used.
@@ -39,11 +40,13 @@ assert-property: ("html", {"scrollTop": "0"})
3940

4041
// We now go back to the crate page to click on the "lib2" crate link.
4142
goto: file://|DOC_PATH|/test_docs/index.html
43+
assert-property: (".sidebar", {"clientWidth": "200"})
4244
assert-css: (".sidebar-elems .crate > ul > li:first-child > a", {"color": "rgb(53, 109, 164)"})
4345
click: ".sidebar-elems .crate > ul > li:first-child > a"
4446

4547
// PAGE: lib2/index.html
4648
goto: file://|DOC_PATH|/lib2/index.html
49+
assert-property: (".sidebar", {"clientWidth": "200"})
4750
assert-text: (".sidebar > .location", "Crate lib2")
4851
// We check that we have the crates list and that the "current" on is now "lib2".
4952
assert-text: (".sidebar-elems .crate > ul > li > a.current", "lib2")
@@ -65,11 +68,13 @@ assert-text: (".sidebar .sidebar-elems .location", "In lib2")
6568
assert-false: ".sidebar-elems > .crate"
6669

6770
goto: ./module/index.html
71+
assert-property: (".sidebar", {"clientWidth": "200"})
6872
assert-text: (".sidebar > .location", "Module module")
6973
// We check that we don't have the crate list.
7074
assert-false: ".sidebar-elems > .crate"
7175

7276
goto: ./sub_module/sub_sub_module/index.html
77+
assert-property: (".sidebar", {"clientWidth": "200"})
7378
assert-text: (".sidebar > .location", "Module sub_sub_module")
7479
// We check that we don't have the crate list.
7580
assert-false: ".sidebar-elems .crate"
@@ -78,11 +83,21 @@ assert-text: ("#functions + .item-table .item-left > a", "foo")
7883

7984
// Links to trait implementations in the sidebar should not wrap even if they are long.
8085
goto: file://|DOC_PATH|/lib2/struct.HasALongTraitWithParams.html
86+
assert-property: (".sidebar", {"clientWidth": "200"})
8187
assert-property: (".sidebar-elems section .block li > a", {"offsetHeight": 29})
8288

8389
// Test that clicking on of the "In <module>" headings in the sidebar links to the
8490
// appropriate anchor in index.html.
8591
goto: file://|DOC_PATH|/test_docs/struct.Foo.html
92+
assert-property: (".sidebar", {"clientWidth": "200"})
8693
click: ".block.mod h3 a"
8794
// PAGE: index.html
8895
assert-css: ("#modules", {"background-color": "rgb(253, 255, 211)"})
96+
97+
// Finally, assert that the `[+]/[−]` toggle doesn't affect sidebar width.
98+
click: "#toggle-all-docs"
99+
assert-text: ("#toggle-all-docs", "[+]")
100+
assert-property: (".sidebar", {"clientWidth": "200"})
101+
click: "#toggle-all-docs"
102+
assert-text: ("#toggle-all-docs", "[−]")
103+
assert-property: (".sidebar", {"clientWidth": "200"})

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ assert-property: (".item-table .struct", {"offsetWidth": "684"})
1515
goto: file://|DOC_PATH|/lib2/too_long/type.ReallyLongTypeNameLongLongLong.html
1616
assert-property: ("body", {"scrollWidth": "1100"})
1717
// We now check that the section width hasn't grown because of it.
18-
assert-property: ("#main-content", {"scrollWidth": "825"})
18+
assert-property: ("#main-content", {"scrollWidth": "840"})
1919
// And now checking that it has scrollable content.
2020
assert-property: (".item-decl pre", {"scrollWidth": "1103"})
2121

@@ -24,7 +24,7 @@ assert-property: (".item-decl pre", {"scrollWidth": "1103"})
2424
goto: file://|DOC_PATH|/lib2/too_long/constant.ReallyLongTypeNameLongLongLongConstBecauseWhyNotAConstRightGigaGigaSupraLong.html
2525
assert-property: ("body", {"scrollWidth": "1100"})
2626
// We now check that the section width hasn't grown because of it.
27-
assert-property: ("#main-content", {"scrollWidth": "825"})
27+
assert-property: ("#main-content", {"scrollWidth": "840"})
2828
// And now checking that it has scrollable content.
2929
assert-property: (".item-decl pre", {"scrollWidth": "950"})
3030

0 commit comments

Comments
 (0)