about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2023-04-23 20:06:30 +0200
committerGitHub <noreply@github.com>2023-04-23 20:06:30 +0200
commit4064bdd914fa3d6c08e821487c77c177188b6fbb (patch)
treef393d69a2dff4070a95bfd6413540dc8c40d07a6
parent915aa06700af4a2363639bae70201cd7387470ad (diff)
parent1d0f34fd771004ed515cb7120df1898c2ef5322e (diff)
downloadrust-4064bdd914fa3d6c08e821487c77c177188b6fbb.tar.gz
rust-4064bdd914fa3d6c08e821487c77c177188b6fbb.zip
Rollup merge of #110661 - notriddle:notriddle/settings-js-handlekey, r=GuillaumeGomez
rustdoc: clean up settings.css and settings.js

`handleKey` was added in 9dc5dfb97504c538bc72f367a77bb9f714c30097 and 704050da2334c465784954d81c8990c4bc7a92c5 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 #110205
-rw-r--r--src/librustdoc/html/static/css/settings.css1
-rw-r--r--src/librustdoc/html/static/js/settings.js19
-rw-r--r--tests/rustdoc-gui/settings.goml9
3 files changed, 10 insertions, 19 deletions
diff --git a/src/librustdoc/html/static/css/settings.css b/src/librustdoc/html/static/css/settings.css
index d13c783d2e4..99cf8e443f0 100644
--- a/src/librustdoc/html/static/css/settings.css
+++ b/src/librustdoc/html/static/css/settings.css
@@ -7,7 +7,6 @@
 	margin-right: 0.3em;
 	height: 1.2rem;
 	width: 1.2rem;
-	color: inherit;
 	border: 2px solid var(--settings-input-border-color);
 	outline: none;
 	-webkit-appearance: none;
diff --git a/src/librustdoc/html/static/js/settings.js b/src/librustdoc/html/static/js/settings.js
index ebbe6c1ca9a..2cba32c1b50 100644
--- a/src/librustdoc/html/static/js/settings.js
+++ b/src/librustdoc/html/static/js/settings.js
@@ -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;
diff --git a/tests/rustdoc-gui/settings.goml b/tests/rustdoc-gui/settings.goml
index 733be9bebba..a44ff9d3e4a 100644
--- a/tests/rustdoc-gui/settings.goml
+++ b/tests/rustdoc-gui/settings.goml
@@ -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: "?"