From 2124217497a630f71587ccb618d18632e1996abc Mon Sep 17 00:00:00 2001 From: Stan Ulbrych Date: Thu, 11 Dec 2025 21:16:22 +0000 Subject: [PATCH] Make toggle switches keyboard accessible --- Lib/profiling/sampling/_heatmap_assets/heatmap.css | 4 ++++ Lib/profiling/sampling/_heatmap_assets/heatmap.js | 6 +++++- .../sampling/_heatmap_assets/heatmap_pyfile_template.html | 6 +++--- Lib/profiling/sampling/_shared_assets/base.css | 3 ++- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Lib/profiling/sampling/_heatmap_assets/heatmap.css b/Lib/profiling/sampling/_heatmap_assets/heatmap.css index 3094279520ab13..37e846c590ebc7 100644 --- a/Lib/profiling/sampling/_heatmap_assets/heatmap.css +++ b/Lib/profiling/sampling/_heatmap_assets/heatmap.css @@ -700,6 +700,10 @@ opacity: 0.85; } +.toggle-switch:focus-visible { + border-radius: 4px; +} + .toggle-switch .toggle-label { font-size: 11px; font-weight: 500; diff --git a/Lib/profiling/sampling/_heatmap_assets/heatmap.js b/Lib/profiling/sampling/_heatmap_assets/heatmap.js index 9cedb2d84698b6..038aa44b3df619 100644 --- a/Lib/profiling/sampling/_heatmap_assets/heatmap.js +++ b/Lib/profiling/sampling/_heatmap_assets/heatmap.js @@ -733,7 +733,7 @@ function toggleAllBytecode() { } } -// Keyboard shortcut: 'b' toggles all bytecode panels +// Keyboard shortcut: 'b' toggles all bytecode panels, Enter/Space activates toggle switches document.addEventListener('keydown', function(e) { if (e.target.tagName === 'INPUT' || e.target.tagName === 'TEXTAREA') { return; @@ -741,6 +741,10 @@ document.addEventListener('keydown', function(e) { if (e.key === 'b' && !e.ctrlKey && !e.altKey && !e.metaKey) { toggleAllBytecode(); } + if ((e.key === 'Enter' || e.key === ' ') && e.target.classList.contains('toggle-switch')) { + e.preventDefault(); + e.target.click(); + } }); // Handle hash changes diff --git a/Lib/profiling/sampling/_heatmap_assets/heatmap_pyfile_template.html b/Lib/profiling/sampling/_heatmap_assets/heatmap_pyfile_template.html index 9e57643d59ff9a..3e80486cb5dbd4 100644 --- a/Lib/profiling/sampling/_heatmap_assets/heatmap_pyfile_template.html +++ b/Lib/profiling/sampling/_heatmap_assets/heatmap_pyfile_template.html @@ -70,17 +70,17 @@
-
+
Self Time
Total Time
-
+
Show All
Hot Only
-
+
Heat
Specialization diff --git a/Lib/profiling/sampling/_shared_assets/base.css b/Lib/profiling/sampling/_shared_assets/base.css index 4117cbb8f2fd50..fee08a8fcfc2c0 100644 --- a/Lib/profiling/sampling/_shared_assets/base.css +++ b/Lib/profiling/sampling/_shared_assets/base.css @@ -385,7 +385,8 @@ body { button:focus-visible, select:focus-visible, -input:focus-visible { +input:focus-visible, +.toggle-switch:focus-visible { outline: 2px solid var(--python-gold); outline-offset: 2px; }