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

rustdoc: fix current class on sidebar modnav #127932

Merged
merged 2 commits into from
Jul 19, 2024
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
8 changes: 5 additions & 3 deletions src/librustdoc/html/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -529,11 +529,13 @@ function preLoadCss(cssUrl) {
}
const link = document.createElement("a");
link.href = path;
if (path === current_page) {
link.className = "current";
}
link.textContent = name;
const li = document.createElement("li");
// Don't "optimize" this to just use `path`.
notriddle marked this conversation as resolved.
Show resolved Hide resolved
// We want the browser to normalize this into an absolute URL.
if (link.href === current_page) {
li.classList.add("current");
}
li.appendChild(link);
ul.appendChild(li);
}
Expand Down
4 changes: 4 additions & 0 deletions tests/rustdoc-gui/sidebar.goml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ click: "#structs + .item-table .item-name > a"
assert-count: (".sidebar .sidebar-crate", 1)
assert-count: (".sidebar .location", 1)
assert-count: (".sidebar h2", 3)
assert-text: (".sidebar-elems ul.block > li.current > a", "Foo")
// We check that there is no crate listed outside of the top level.
assert-false: ".sidebar-elems > .crate"

Expand Down Expand Up @@ -110,6 +111,7 @@ click: "#functions + .item-table .item-name > a"
assert-text: (".sidebar > .sidebar-crate > h2 > a", "lib2")
assert-count: (".sidebar .location", 0)
assert-count: (".sidebar h2", 1)
assert-text: (".sidebar-elems ul.block > li.current > a", "foobar")
// We check that we don't have the crate list.
assert-false: ".sidebar-elems > .crate"

Expand All @@ -118,6 +120,7 @@ assert-property: (".sidebar", {"clientWidth": "200"})
assert-text: (".sidebar > .sidebar-crate > h2 > a", "lib2")
assert-text: (".sidebar > .location", "Module module")
assert-count: (".sidebar .location", 1)
assert-text: (".sidebar-elems ul.block > li.current > a", "module")
// Module page requires three headings:
// - Presistent crate branding (name and version)
// - Module name, followed by TOC for module headings
Expand All @@ -138,6 +141,7 @@ assert-text: (".sidebar > .sidebar-elems > h2", "In lib2::module::sub_module")
assert-property: (".sidebar > .sidebar-elems > h2 > a", {
"href": "/module/sub_module/index.html",
}, ENDS_WITH)
assert-text: (".sidebar-elems ul.block > li.current > a", "sub_sub_module")
// We check that we don't have the crate list.
assert-false: ".sidebar-elems .crate"
assert-text: (".sidebar-elems > section ul > li:nth-child(1)", "Functions")
Expand Down
Loading