1212
1313// Used when we need to generate ids for ARIA.
1414var 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
1624function 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+
2750function 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
6998function 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
0 commit comments