Skip to content

Commit 6ca314e

Browse files
committed
rustdoc: make source sidebar toggle a real button
This fixes tab focus, so that you can open and close the sidebar from keyboard.
1 parent 3073109 commit 6ca314e

File tree

5 files changed

+23
-8
lines changed

5 files changed

+23
-8
lines changed

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

+17-2
Original file line numberDiff line numberDiff line change
@@ -1370,7 +1370,6 @@ pre.rust {
13701370
position: sticky;
13711371
top: 0;
13721372
left: 0;
1373-
cursor: pointer;
13741373
font-weight: bold;
13751374
font-size: 1.25rem;
13761375
border-bottom: 1px solid;
@@ -1391,7 +1390,23 @@ pre.rust {
13911390
border-bottom: 1px solid;
13921391
margin-bottom: 6px;
13931392
}
1394-
1393+
#sidebar-toggle > button {
1394+
background: none;
1395+
color: inherit;
1396+
cursor: pointer;
1397+
text-align: center;
1398+
border: none;
1399+
outline: none;
1400+
position: absolute;
1401+
top: 0;
1402+
bottom: 0;
1403+
left: 0;
1404+
right: 0;
1405+
width: 100%;
1406+
/* iOS button gradient: https://stackoverflow.com/q/5438567 */
1407+
-webkit-appearance: none;
1408+
opacity: 1;
1409+
}
13951410
#settings-menu, #help-button {
13961411
margin-left: 4px;
13971412
outline: none;

src/librustdoc/html/static/css/themes/ayu.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ kbd {
620620
#sidebar-toggle {
621621
background-color: #14191f;
622622
}
623-
#sidebar-toggle:hover {
623+
#sidebar-toggle:hover, #sidebar-toggle > button:focus {
624624
background-color: rgba(70, 70, 70, 0.33);
625625
}
626626
#source-sidebar {

src/librustdoc/html/static/css/themes/dark.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ kbd {
491491
#sidebar-toggle {
492492
background-color: #565656;
493493
}
494-
#sidebar-toggle:hover {
494+
#sidebar-toggle:hover, #sidebar-toggle > button:focus {
495495
background-color: #676767;
496496
}
497497
#source-sidebar {

src/librustdoc/html/static/css/themes/light.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ kbd {
475475
#sidebar-toggle {
476476
background-color: #F5F5F5;
477477
}
478-
#sidebar-toggle:hover {
478+
#sidebar-toggle:hover, #sidebar-toggle > button:focus {
479479
background-color: #E0E0E0;
480480
}
481481
#source-sidebar {

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function createDirEntry(elem, parent, fullPath, hasFoundFile) {
6464
}
6565

6666
function toggleSidebar() {
67-
const child = this.children[0];
67+
const child = this.parentNode.children[0];
6868
if (child.innerText === ">") {
6969
if (window.innerWidth < window.RUSTDOC_MOBILE_BREAKPOINT) {
7070
// This is to keep the scroll position on mobile.
@@ -107,15 +107,15 @@ window.addEventListener("resize", () => {
107107
function createSidebarToggle() {
108108
const sidebarToggle = document.createElement("div");
109109
sidebarToggle.id = "sidebar-toggle";
110-
sidebarToggle.onclick = toggleSidebar;
111110

112-
const inner = document.createElement("div");
111+
const inner = document.createElement("button");
113112

114113
if (getCurrentValue("source-sidebar-show") === "true") {
115114
inner.innerText = "<";
116115
} else {
117116
inner.innerText = ">";
118117
}
118+
inner.onclick = toggleSidebar;
119119

120120
sidebarToggle.appendChild(inner);
121121
return sidebarToggle;

0 commit comments

Comments
 (0)