Skip to content

Commit b1c9582

Browse files
gh-138122: Tachyon heatmap: Make toggle switches keyboard accessible (#142601)
1 parent 2eca80f commit b1c9582

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

Lib/profiling/sampling/_heatmap_assets/heatmap.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,10 @@
682682
opacity: 0.85;
683683
}
684684

685+
.toggle-switch:focus-visible {
686+
border-radius: 4px;
687+
}
688+
685689
.toggle-switch .toggle-label {
686690
font-size: 11px;
687691
font-weight: 500;

Lib/profiling/sampling/_heatmap_assets/heatmap.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -733,14 +733,18 @@ function toggleAllBytecode() {
733733
}
734734
}
735735

736-
// Keyboard shortcut: 'b' toggles all bytecode panels
736+
// Keyboard shortcut: 'b' toggles all bytecode panels, Enter/Space activates toggle switches
737737
document.addEventListener('keydown', function(e) {
738738
if (e.target.tagName === 'INPUT' || e.target.tagName === 'TEXTAREA') {
739739
return;
740740
}
741741
if (e.key === 'b' && !e.ctrlKey && !e.altKey && !e.metaKey) {
742742
toggleAllBytecode();
743743
}
744+
if ((e.key === 'Enter' || e.key === ' ') && e.target.classList.contains('toggle-switch')) {
745+
e.preventDefault();
746+
e.target.click();
747+
}
744748
});
745749

746750
// Handle hash changes

Lib/profiling/sampling/_heatmap_assets/heatmap_pyfile_template.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,17 @@
7070
</div>
7171
<div class="legend-separator" aria-hidden="true"></div>
7272
<div class="legend-controls">
73-
<div class="toggle-switch" id="toggle-color-mode" title="Toggle between self time and total time coloring">
73+
<div class="toggle-switch" id="toggle-color-mode" title="Toggle between self time and total time coloring" tabindex="0">
7474
<span class="toggle-label active" data-text="Self Time">Self Time</span>
7575
<div class="toggle-track"></div>
7676
<span class="toggle-label" data-text="Total Time">Total Time</span>
7777
</div>
78-
<div class="toggle-switch" id="toggle-cold" title="Toggle visibility of lines with zero samples">
78+
<div class="toggle-switch" id="toggle-cold" title="Toggle visibility of lines with zero samples" tabindex="0">
7979
<span class="toggle-label active" data-text="Show All">Show All</span>
8080
<div class="toggle-track"></div>
8181
<span class="toggle-label" data-text="Hot Only">Hot Only</span>
8282
</div>
83-
<div class="toggle-switch" id="toggle-spec-view" title="Color lines by specialization level (requires bytecode data)">
83+
<div class="toggle-switch" id="toggle-spec-view" title="Color lines by specialization level (requires bytecode data)" tabindex="0">
8484
<span class="toggle-label active" data-text="Heat">Heat</span>
8585
<div class="toggle-track"></div>
8686
<span class="toggle-label" data-text="Specialization">Specialization</span>

Lib/profiling/sampling/_shared_assets/base.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ body {
387387
button:focus-visible,
388388
select:focus-visible,
389389
input:focus-visible,
390+
.toggle-switch:focus-visible,
390391
a.toolbar-btn:focus-visible {
391392
outline: 2px solid var(--python-gold);
392393
outline-offset: 2px;

0 commit comments

Comments
 (0)