Skip to content

Commit 05ad133

Browse files
Rollup merge of rust-lang#110661 - notriddle:notriddle/settings-js-handlekey, r=GuillaumeGomez
rustdoc: clean up settings.css and settings.js `handleKey` was added in 9dc5dfb and 704050d because the browser-native checkbox was `display: none`, breaking native keyboard accessibility. The native checkbox is now merely `appearance: none`, which does not turn off [behavior semantics], so JavaScript to reimplement it isn't needed any more. [behavior semantics]: https://w3c.github.io/csswg-drafts/css-ui/#appearance-semantics The other, one line change to settings.css is follow-up to rust-lang#110205
2 parents ab1c930 + 1d0f34f commit 05ad133

File tree

3 files changed

+10
-19
lines changed

3 files changed

+10
-19
lines changed

src/librustdoc/html/static/css/settings.css

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
margin-right: 0.3em;
88
height: 1.2rem;
99
width: 1.2rem;
10-
color: inherit;
1110
border: 2px solid var(--settings-input-border-color);
1211
outline: none;
1312
-webkit-appearance: none;

src/librustdoc/html/static/js/settings.js

+1-18
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Local js definitions:
2-
/* global getSettingValue, getVirtualKey, updateLocalStorage, updateTheme */
2+
/* global getSettingValue, updateLocalStorage, updateTheme */
33
/* global addClass, removeClass, onEach, onEachLazy, blurHandler, elemIsInParent */
44
/* global MAIN_ID, getVar, getSettingsButton */
55

@@ -32,21 +32,6 @@
3232
}
3333
}
3434

35-
function handleKey(ev) {
36-
// Don't interfere with browser shortcuts
37-
if (ev.ctrlKey || ev.altKey || ev.metaKey) {
38-
return;
39-
}
40-
switch (getVirtualKey(ev)) {
41-
case "Enter":
42-
case "Return":
43-
case "Space":
44-
ev.target.checked = !ev.target.checked;
45-
ev.preventDefault();
46-
break;
47-
}
48-
}
49-
5035
function showLightAndDark() {
5136
removeClass(document.getElementById("preferred-light-theme"), "hidden");
5237
removeClass(document.getElementById("preferred-dark-theme"), "hidden");
@@ -77,8 +62,6 @@
7762
toggle.onchange = function() {
7863
changeSetting(this.id, this.checked);
7964
};
80-
toggle.onkeyup = handleKey;
81-
toggle.onkeyrelease = handleKey;
8265
});
8366
onEachLazy(settingsElement.querySelectorAll("input[type=\"radio\"]"), elem => {
8467
const settingId = elem.name;

tests/rustdoc-gui/settings.goml

+9
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,15 @@ set-local-storage: {"rustdoc-disable-shortcuts": "false"}
256256
click: ".setting-line:last-child .setting-check span"
257257
assert-local-storage: {"rustdoc-disable-shortcuts": "true"}
258258

259+
// We now check that focusing a toggle and pressing Space is like clicking on it.
260+
assert-local-storage: {"rustdoc-disable-shortcuts": "true"}
261+
focus: ".setting-line:last-child .setting-check input"
262+
press-key: "Space"
263+
assert-local-storage: {"rustdoc-disable-shortcuts": "false"}
264+
focus: ".setting-line:last-child .setting-check input"
265+
press-key: "Space"
266+
assert-local-storage: {"rustdoc-disable-shortcuts": "true"}
267+
259268
// Make sure that "Disable keyboard shortcuts" actually took effect.
260269
press-key: "Escape"
261270
press-key: "?"

0 commit comments

Comments
 (0)