Skip to content

Commit b718ef2

Browse files
committed
Trello: Make checklists accessible.
1 parent c6dcd56 commit b718ef2

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

TrelloA11yFixes.user.js

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@
1212

1313
// Used when we need to generate ids for ARIA.
1414
var idCounter = 0;
15+
// Get a node's id. If it doesn't have one, make and set one first.
16+
function getAriaId(elem) {
17+
if (elem.id) {
18+
return elem.id;
19+
}
20+
elem.setAttribute("id", "axsg-" + idCounter++);
21+
return elem.id;
22+
}
1523

1624
function makeHeading(elem, level) {
1725
elem.setAttribute("role", "heading");
@@ -24,6 +32,21 @@ function tweakCard(card) {
2432
card.setAttribute("role", "listitem");
2533
}
2634

35+
// Make checklists accessible.
36+
function tweakCheckItem(checkItem, isNew) {
37+
var checkbox = checkItem.querySelector(".checklist-item-checkbox-check");
38+
if (isNew) {
39+
checkbox.setAttribute("role", "checkbox");
40+
checkbox.setAttribute("tabindex", "-1");
41+
var checkLabel = checkItem.querySelector(".checklist-item-details-text");
42+
if (checkLabel) {
43+
checkbox.setAttribute("aria-labelledby", getAriaId(checkLabel));
44+
}
45+
}
46+
var complete = checkItem.classList.contains("checklist-item-state-complete");
47+
checkbox.setAttribute("aria-checked", complete ? "true" : "false");
48+
}
49+
2750
function onNodeAdded(target) {
2851
if (target.classList.contains("list-card")) {
2952
// A card just got added.
@@ -44,14 +67,17 @@ function onNodeAdded(target) {
4467
target.blur();
4568
return;
4669
}
70+
if (target.classList.contains("checklist-item")) {
71+
// A checklist item just got added.
72+
tweakCheckItem(target, true);
73+
return;
74+
}
4775
for (var list of target.querySelectorAll(".list")) {
4876
list.setAttribute("role", "list");
4977
var header = list.querySelector(".list-header-name");
5078
if (header) {
5179
// Label the list with its header.
52-
var id = "axsg-lh" + idCounter++;
53-
header.setAttribute("id", id);
54-
list.setAttribute("aria-labelledby", id);
80+
list.setAttribute("aria-labelledby", getAriaId(header));
5581
// Make the header's container into a heading.
5682
makeHeading(header, 2);
5783
}
@@ -64,6 +90,9 @@ function onNodeAdded(target) {
6490
// to facilitate quick jumping between activity items.
6591
makeHeading(activityCreator, 4);
6692
}
93+
for (var checkItem of target.querySelectorAll(".checklist-item")) {
94+
tweakCheckItem(checkItem, true);
95+
}
6796
}
6897

6998
function onClassModified(target) {
@@ -73,6 +102,8 @@ function onClassModified(target) {
73102
if (classes.contains("active-card")) {
74103
// When the active card changes, focus it.
75104
target.focus();
105+
} else if (classes.contains("checklist-item")) {
106+
tweakCheckItem(target, false);
76107
}
77108
}
78109

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,4 @@ It does the following:
9898
- Makes list headers and activity item headers accessible as headings.
9999
- Prevents loss of position for screen reader users when pressing the control key.
100100
- Adds a shift+m keyboard shortcut to quickly move a card.
101+
- Makes checklists accessible.

0 commit comments

Comments
 (0)