rustdoc: remove unneeded handleKey from settings.js

This code was added in 9dc5dfb975
and 704050da23 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
This commit is contained in:
Michael Howell 2023-04-21 16:28:05 -07:00
parent fec9adcdbc
commit 5cefe75436
2 changed files with 10 additions and 18 deletions

View File

@ -1,5 +1,5 @@
// Local js definitions:
/* global getSettingValue, getVirtualKey, updateLocalStorage, updateTheme */
/* global getSettingValue, updateLocalStorage, updateTheme */
/* global addClass, removeClass, onEach, onEachLazy, blurHandler, elemIsInParent */
/* global MAIN_ID, getVar, getSettingsButton */
@ -32,21 +32,6 @@
}
}
function handleKey(ev) {
// Don't interfere with browser shortcuts
if (ev.ctrlKey || ev.altKey || ev.metaKey) {
return;
}
switch (getVirtualKey(ev)) {
case "Enter":
case "Return":
case "Space":
ev.target.checked = !ev.target.checked;
ev.preventDefault();
break;
}
}
function showLightAndDark() {
removeClass(document.getElementById("preferred-light-theme"), "hidden");
removeClass(document.getElementById("preferred-dark-theme"), "hidden");
@ -77,8 +62,6 @@
toggle.onchange = function() {
changeSetting(this.id, this.checked);
};
toggle.onkeyup = handleKey;
toggle.onkeyrelease = handleKey;
});
onEachLazy(settingsElement.querySelectorAll("input[type=\"radio\"]"), elem => {
const settingId = elem.name;

View File

@ -256,6 +256,15 @@ set-local-storage: {"rustdoc-disable-shortcuts": "false"}
click: ".setting-line:last-child .setting-check span"
assert-local-storage: {"rustdoc-disable-shortcuts": "true"}
// We now check that focusing a toggle and pressing Space is like clicking on it.
assert-local-storage: {"rustdoc-disable-shortcuts": "true"}
focus: ".setting-line:last-child .setting-check input"
press-key: "Space"
assert-local-storage: {"rustdoc-disable-shortcuts": "false"}
focus: ".setting-line:last-child .setting-check input"
press-key: "Space"
assert-local-storage: {"rustdoc-disable-shortcuts": "true"}
// Make sure that "Disable keyboard shortcuts" actually took effect.
press-key: "Escape"
press-key: "?"