Skip to content

Commit ca3b4c6

Browse files
Rollup merge of rust-lang#98092 - GuillaumeGomez:fix-sidebar-items-expand-collapse, r=notriddle
Fix sidebar items expand collapse The collapse/expand event was not working for the items in the source code viewer sidebar (talking about these items: ![Screenshot from 2022-06-14 11-21-58](https://user-images.githubusercontent.com/3050060/173543346-af056928-e921-458f-b918-60f6fd0ecbde.png) ). This PR fixes it and adds a GUI test to prevent another regression. r? ``@notriddle``
2 parents 143fa5e + a70c14a commit ca3b4c6

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

src/librustdoc/html/static/js/source-script.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ function createDirEntry(elem, parent, fullPath, currentFile, hasFoundFile) {
3232
fullPath += elem["name"] + "/";
3333

3434
name.onclick = () => {
35-
if (hasClass(this, "expand")) {
36-
removeClass(this, "expand");
35+
if (hasClass(name, "expand")) {
36+
removeClass(name, "expand");
3737
} else {
38-
addClass(this, "expand");
38+
addClass(name, "expand");
3939
}
4040
};
4141
name.innerText = elem["name"];

src/test/rustdoc-gui/source-code-page.goml

+24-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Checks that the interactions with the source code pages are workined as expected.
1+
// Checks that the interactions with the source code pages are working as expected.
22
goto: file://|DOC_PATH|/src/test_docs/lib.rs.html
33
// Check that we can click on the line number.
44
click: ".line-numbers > span:nth-child(4)" // This is the span for line 4.
@@ -27,3 +27,26 @@ assert-position: ("//*[@id='1']", {"x": 104, "y": 103})
2727
// We click on the left of the "1" span but still in the "line-number" `<pre>`.
2828
click: (103, 103)
2929
assert-document-property: ({"URL": "/lib.rs.html"}, ENDS_WITH)
30+
31+
// Checking the source code sidebar.
32+
33+
// First we "open" it.
34+
click: "#sidebar-toggle"
35+
assert: ".sidebar.expanded"
36+
37+
// We check that the first entry of the sidebar is collapsed (which, for whatever reason,
38+
// is number 2 and not 1...).
39+
assert-attribute: ("#source-sidebar .name:nth-child(2)", {"class": "name"})
40+
assert-text: ("#source-sidebar .name:nth-child(2)", "implementors")
41+
// We also check its children are hidden too.
42+
assert-css: ("#source-sidebar .name:nth-child(2) + .children", {"display": "none"})
43+
// We now click on it.
44+
click: "#source-sidebar .name:nth-child(2)"
45+
assert-attribute: ("#source-sidebar .name:nth-child(2)", {"class": "name expand"})
46+
// Checking that its children are displayed as well.
47+
assert-css: ("#source-sidebar .name:nth-child(2) + .children", {"display": "block"})
48+
49+
// And now we collapse it again.
50+
click: "#source-sidebar .name:nth-child(2)"
51+
assert-attribute: ("#source-sidebar .name:nth-child(2)", {"class": "name"})
52+
assert-css: ("#source-sidebar .name:nth-child(2) + .children", {"display": "none"})

0 commit comments

Comments
 (0)