Commit a584509
committed
Make CheckboxTree view accessible.
1. The keyboard can now be used to move through the tree, expand and collapse nodes:
* Home / end moves to the first and last visible node, respectively.
* Up / down arrows moves to the previous / next visible node.
* Right arrow expands a collapsed node, if focus is on a collapsed parent. If focus is on an expanded parent, move to its first child.
* Left arrow collapses the node if focus is on an expanded parent. Otherwise, focus is moved to the parent of the currently focused node.
* First letter navigation: for example, press R to move focus to the next node who's label starts with R.
* Space toggles selection, as expected for a checkbox.
This is implemented by computing an in-order traversal of visible nodes updated each render which greatly simplifies computation for focus movements.
Focus is managed by using the [roving tabindex pattern](https://www.w3.org/TR/wai-aria-practices-1.1/#kbd_roving_tabindex).
* Each TreeNode takes in a new property, `hasFocus` which is initialized to `false` on initial render. This causes each tree item to have `tabindex=-1` set, which excludes them from tab order, but allows them to be programatically focused.
* On initial focus of the top-level `CheckboxTree` component, we initialize the currently focused node index to 0. This causes the first tree node's `hasFocus` to be set to `true`, which sets `tabIndex=0`, so it is included in tab order. `TreeNode`'s `componentDidUpdate` fires a focus event when it is supposed to gain focus.
* Other key presses manipulate the currently focused index, which causes the element with `tabindex=0` to move about, hence the roving tabindex.
2. Add the necessary aria attributes for screen readers to correctly read the state of the tree, whether a node is expanded/collapsed, checked etc.
For more information, see https://www.w3.org/TR/wai-aria-practices-1.1/#TreeView1 parent ab0478c commit a584509
File tree
5 files changed
+184
-19
lines changed- src
- js
- scss
- test
5 files changed
+184
-19
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
15 | 29 | | |
16 | 30 | | |
17 | 31 | | |
| |||
87 | 101 | | |
88 | 102 | | |
89 | 103 | | |
| 104 | + | |
90 | 105 | | |
91 | 106 | | |
92 | 107 | | |
| |||
97 | 112 | | |
98 | 113 | | |
99 | 114 | | |
| 115 | + | |
| 116 | + | |
100 | 117 | | |
101 | 118 | | |
102 | 119 | | |
| |||
158 | 175 | | |
159 | 176 | | |
160 | 177 | | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
161 | 258 | | |
162 | 259 | | |
163 | 260 | | |
| |||
207 | 304 | | |
208 | 305 | | |
209 | 306 | | |
210 | | - | |
| 307 | + | |
211 | 308 | | |
212 | 309 | | |
213 | 310 | | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
214 | 318 | | |
215 | 319 | | |
216 | 320 | | |
| |||
223 | 327 | | |
224 | 328 | | |
225 | 329 | | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | 330 | | |
234 | 331 | | |
235 | 332 | | |
| |||
239 | 336 | | |
240 | 337 | | |
241 | 338 | | |
| 339 | + | |
242 | 340 | | |
243 | 341 | | |
244 | 342 | | |
| |||
261 | 359 | | |
262 | 360 | | |
263 | 361 | | |
264 | | - | |
| 362 | + | |
265 | 363 | | |
266 | 364 | | |
267 | 365 | | |
| |||
327 | 425 | | |
328 | 426 | | |
329 | 427 | | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
330 | 431 | | |
331 | 432 | | |
332 | 433 | | |
| |||
339 | 440 | | |
340 | 441 | | |
341 | 442 | | |
342 | | - | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
343 | 452 | | |
344 | 453 | | |
345 | 454 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
34 | 37 | | |
35 | 38 | | |
36 | 39 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
50 | 51 | | |
51 | 52 | | |
52 | 53 | | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
53 | 57 | | |
54 | 58 | | |
| 59 | + | |
55 | 60 | | |
56 | 61 | | |
57 | 62 | | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
58 | 71 | | |
59 | 72 | | |
60 | 73 | | |
| |||
77 | 90 | | |
78 | 91 | | |
79 | 92 | | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
80 | 103 | | |
81 | 104 | | |
82 | 105 | | |
| |||
117 | 140 | | |
118 | 141 | | |
119 | 142 | | |
| 143 | + | |
| 144 | + | |
120 | 145 | | |
121 | 146 | | |
122 | 147 | | |
123 | 148 | | |
| 149 | + | |
124 | 150 | | |
125 | 151 | | |
126 | 152 | | |
| |||
178 | 204 | | |
179 | 205 | | |
180 | 206 | | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
181 | 211 | | |
182 | 212 | | |
183 | 213 | | |
184 | 214 | | |
185 | 215 | | |
186 | 216 | | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | 217 | | |
191 | 218 | | |
192 | 219 | | |
193 | 220 | | |
194 | 221 | | |
195 | 222 | | |
| 223 | + | |
| 224 | + | |
196 | 225 | | |
197 | 226 | | |
198 | 227 | | |
| |||
226 | 255 | | |
227 | 256 | | |
228 | 257 | | |
| 258 | + | |
| 259 | + | |
229 | 260 | | |
230 | 261 | | |
231 | 262 | | |
232 | 263 | | |
233 | 264 | | |
234 | | - | |
235 | | - | |
236 | 265 | | |
237 | 266 | | |
238 | 267 | | |
| |||
267 | 296 | | |
268 | 297 | | |
269 | 298 | | |
270 | | - | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
271 | 306 | | |
272 | 307 | | |
273 | 308 | | |
274 | 309 | | |
| 310 | + | |
275 | 311 | | |
276 | 312 | | |
277 | 313 | | |
| |||
285 | 321 | | |
286 | 322 | | |
287 | 323 | | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
288 | 328 | | |
289 | 329 | | |
290 | | - | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
291 | 340 | | |
292 | 341 | | |
293 | 342 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
8 | 11 | | |
9 | 12 | | |
| 13 | + | |
10 | 14 | | |
11 | 15 | | |
12 | 16 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
178 | 178 | | |
179 | 179 | | |
180 | 180 | | |
181 | | - | |
| 181 | + | |
182 | 182 | | |
183 | 183 | | |
184 | 184 | | |
| |||
0 commit comments