Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sidebar items expand collapse #98092

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/librustdoc/html/static/js/source-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ function createDirEntry(elem, parent, fullPath, currentFile, hasFoundFile) {
fullPath += elem["name"] + "/";

name.onclick = () => {
if (hasClass(this, "expand")) {
removeClass(this, "expand");
if (hasClass(name, "expand")) {
removeClass(name, "expand");
} else {
addClass(this, "expand");
addClass(name, "expand");
}
};
name.innerText = elem["name"];
Expand Down
25 changes: 24 additions & 1 deletion src/test/rustdoc-gui/source-code-page.goml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Checks that the interactions with the source code pages are workined as expected.
// Checks that the interactions with the source code pages are working as expected.
goto: file://|DOC_PATH|/src/test_docs/lib.rs.html
// Check that we can click on the line number.
click: ".line-numbers > span:nth-child(4)" // This is the span for line 4.
Expand Down Expand Up @@ -27,3 +27,26 @@ assert-position: ("//*[@id='1']", {"x": 104, "y": 103})
// We click on the left of the "1" span but still in the "line-number" `<pre>`.
click: (103, 103)
assert-document-property: ({"URL": "/lib.rs.html"}, ENDS_WITH)

// Checking the source code sidebar.

// First we "open" it.
click: "#sidebar-toggle"
assert: ".sidebar.expanded"

// We check that the first entry of the sidebar is collapsed (which, for whatever reason,
// is number 2 and not 1...).
assert-attribute: ("#source-sidebar .name:nth-child(2)", {"class": "name"})
assert-text: ("#source-sidebar .name:nth-child(2)", "implementors")
// We also check its children are hidden too.
assert-css: ("#source-sidebar .name:nth-child(2) + .children", {"display": "none"})
// We now click on it.
click: "#source-sidebar .name:nth-child(2)"
assert-attribute: ("#source-sidebar .name:nth-child(2)", {"class": "name expand"})
// Checking that its children are displayed as well.
assert-css: ("#source-sidebar .name:nth-child(2) + .children", {"display": "block"})

// And now we collapse it again.
click: "#source-sidebar .name:nth-child(2)"
assert-attribute: ("#source-sidebar .name:nth-child(2)", {"class": "name"})
assert-css: ("#source-sidebar .name:nth-child(2) + .children", {"display": "none"})