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: make source sidebar toggle a real button #98774

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
22 changes: 19 additions & 3 deletions src/librustdoc/html/static/css/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ nav.sub {
background-color: var(--sidebar-background-color);
}

#sidebar-toggle:hover {
#sidebar-toggle > button:hover, #sidebar-toggle > button:focus {
background-color: var(--sidebar-background-color-hover);
}

Expand Down Expand Up @@ -1401,7 +1401,6 @@ pre.rust {
position: sticky;
top: 0;
left: 0;
cursor: pointer;
font-weight: bold;
font-size: 1.25rem;
border-bottom: 1px solid;
Expand All @@ -1422,7 +1421,24 @@ pre.rust {
border-bottom: 1px solid;
margin-bottom: 6px;
}

#sidebar-toggle > button {
background: none;
color: inherit;
cursor: pointer;
text-align: center;
border: none;
outline: none;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
/* work around button layout strangeness: https://stackoverflow.com/q/7271561 */
width: 100%;
GuillaumeGomez marked this conversation as resolved.
Show resolved Hide resolved
/* iOS button gradient: https://stackoverflow.com/q/5438567 */
-webkit-appearance: none;
opacity: 1;
}
#settings-menu, #help-button {
margin-left: 4px;
outline: none;
Expand Down
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 @@ -64,7 +64,7 @@ function createDirEntry(elem, parent, fullPath, hasFoundFile) {
}

function toggleSidebar() {
const child = this.children[0];
const child = this.parentNode.children[0];
if (child.innerText === ">") {
if (window.innerWidth < 701) {
// This is to keep the scroll position on mobile.
Expand Down Expand Up @@ -93,15 +93,15 @@ function toggleSidebar() {
function createSidebarToggle() {
const sidebarToggle = document.createElement("div");
sidebarToggle.id = "sidebar-toggle";
sidebarToggle.onclick = toggleSidebar;

const inner = document.createElement("div");
const inner = document.createElement("button");

if (getCurrentValue("source-sidebar-show") === "true") {
inner.innerText = "<";
} else {
inner.innerText = ">";
}
inner.onclick = toggleSidebar;

sidebarToggle.appendChild(inner);
return sidebarToggle;
Expand Down
27 changes: 27 additions & 0 deletions src/test/rustdoc-gui/sidebar-source-code-display.goml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ assert-css: (
"#source-sidebar .expand + .children a.selected",
{"color": "rgb(0, 0, 0)", "background-color": "rgb(255, 255, 255)"},
)
// Without hover or focus.
assert-css: ("#sidebar-toggle > button", {"background-color": "rgba(0, 0, 0, 0)"})
// With focus.
focus: "#sidebar-toggle > button"
assert-css: ("#sidebar-toggle > button", {"background-color": "rgb(224, 224, 224)"})
focus: ".search-input"
// With hover.
move-cursor-to: "#sidebar-toggle > button"
assert-css: ("#sidebar-toggle > button", {"background-color": "rgb(224, 224, 224)"})
// Without hover.
assert-css: (
"#source-sidebar .expand + .children > .files a:not(.selected)",
Expand Down Expand Up @@ -62,6 +71,15 @@ assert-css: (
"#source-sidebar .expand + .children a.selected",
{"color": "rgb(221, 221, 221)", "background-color": "rgb(51, 51, 51)"},
)
// Without hover or focus.
assert-css: ("#sidebar-toggle > button", {"background-color": "rgba(0, 0, 0, 0)"})
// With focus.
focus: "#sidebar-toggle > button"
assert-css: ("#sidebar-toggle > button", {"background-color": "rgb(103, 103, 103)"})
focus: ".search-input"
// With hover.
move-cursor-to: "#sidebar-toggle > button"
assert-css: ("#sidebar-toggle > button", {"background-color": "rgb(103, 103, 103)"})
// Without hover.
assert-css: (
"#source-sidebar .expand + .children > .files a:not(.selected)",
Expand Down Expand Up @@ -94,6 +112,15 @@ assert-css: (
"#source-sidebar .expand + .children a.selected",
{"color": "rgb(255, 180, 76)", "background-color": "rgb(20, 25, 31)"},
)
// Without hover or focus.
assert-css: ("#sidebar-toggle > button", {"background-color": "rgba(0, 0, 0, 0)"})
// With focus.
focus: "#sidebar-toggle > button"
assert-css: ("#sidebar-toggle > button", {"background-color": "rgba(70, 70, 70, 0.33)"})
focus: ".search-input"
// With hover.
move-cursor-to: "#sidebar-toggle > button"
assert-css: ("#sidebar-toggle > button", {"background-color": "rgba(70, 70, 70, 0.33)"})
// Without hover.
assert-css: (
"#source-sidebar .expand + .children > .files a:not(.selected)",
Expand Down