Skip to content

Commit 03e24f3

Browse files
Make table sorting reachable by keyboard
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent a95a3ba commit 03e24f3

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

‎docs/overrides/assets/javascripts/tablesort.js‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,16 @@ document$.subscribe(function () {
1313
}
1414
new Tablesort(table);
1515

16-
// Tablesort makes header cells focusable (tabindex=0) and sorts on click,
17-
// but does not handle keyboard activation. Let Enter/Space sort too, so the
18-
// sortable headers are usable without a mouse. Cover both th and td header
19-
// cells, since a thead synthesized from the first row may hold td cells.
16+
// Tablesort binds clicks to sortable headers. Make those cells focusable
17+
// before adding Enter/Space activation. A synthesized thead may contain td.
2018
table.querySelectorAll("thead th, thead td").forEach(function (header) {
19+
if (
20+
header.getAttribute("role") !== "columnheader" ||
21+
header.getAttribute("data-sort-method") === "none"
22+
) {
23+
return;
24+
}
25+
header.tabIndex = 0;
2126
header.addEventListener("keydown", function (event) {
2227
if (event.key === "Enter" || event.key === " ") {
2328
event.preventDefault();

0 commit comments

Comments
 (0)