Skip to content

Commit e0a802f

Browse files
author
Alice
authored
Merge pull request #64 from alice/computed
Clarify ARIA, AOM and computed attributes
2 parents 17acc87 + 0708c2a commit e0a802f

File tree

1 file changed

+95
-49
lines changed

1 file changed

+95
-49
lines changed

explainer.md

Lines changed: 95 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,16 @@
2121
- [The Accessibility Object Model](#the-accessibility-object-model)
2222
- [Phase 1: Modifying Accessible Properties](#phase-1-modifying-accessible-properties)
2323
- [Use cases for Accessible Properties](#use-cases-for-accessible-properties)
24-
- [No reflection](#no-reflection)
24+
- [AOM and ARIA](#aom-and-aria)
25+
- [No reflection](#no-reflection)
26+
- [ARIA takes precedence](#aria-takes-precedence)
27+
- [Reasoning](#reasoning)
2528
- [Computed accessible properties](#computed-accessible-properties)
2629
- [Validation](#validation)
2730
- [Phase 2: Accessible Actions](#phase-2-accessible-actions)
2831
- [Phase 3: Virtual Accessibility Nodes](#phase-3-virtual-accessibility-nodes)
2932
- [Phase 4: Full Introspection of an Accessibility Tree](#phase-4-full-introspection-of-an-accessibility-tree)
33+
- [Why is accessing the computed properties being addressed last?](#why-is-accessing-the-computed-properties-being-addressed-last)
3034
- [Phases: Summary](#phases-summary)
3135
- [Audience for the proposed API](#audience-for-the-proposed-api)
3236
- [Next Steps](#next-steps)
@@ -42,6 +46,10 @@ This effort aims to create a JavaScript API
4246
to allow developers to modify (and eventually explore) the accessibility tree
4347
for an HTML page.
4448

49+
If you're already familiar with the accessibility tree and ARIA,
50+
[The Accessibility Object Model](#the-accessibility-object-model)
51+
section is the discussion of the actual proposal.
52+
4553
## Background: assistive technology and the accessibility tree
4654

4755
Assistive technology, in this context, refers to a third party application
@@ -190,7 +198,7 @@ or can't be achieved without cumbersome workarounds.
190198

191199
## The Accessibility Object Model
192200

193-
This spec proposes the *Accessibility Object Model*.
201+
This spec proposes the *Accessibility Object Model* (AOM).
194202
We plan to split this work into four phases,
195203
which will respectively allow authors to:
196204

@@ -341,70 +349,80 @@ input.accessibleNode.activeDescendant = optionList.accessibleNode;
341349

342350
This would allow the relationship to be expressed naturally.
343351

344-
#### No reflection
352+
#### AOM and ARIA
353+
354+
While AOM and ARIA both affect the computed accessible properties of a node,
355+
and have the same vocabulary,
356+
they are separate interfaces.
345357

346-
Even though there's correspondence between Accessible Properties and
347-
ARIA attributes, they are never reflected. Similarly, Accessible Properties
348-
do not reflect equivalent implicit properties of their associated DOM elements,
349-
either.
358+
##### No reflection
359+
360+
ARIA does not reflect to AOM:
361+
362+
```html
363+
<div "clickBtn" role="button">Click here</div>
364+
```
350365

351366
```js
352-
button = document.createElement("button");
353-
button.innerHTML = "Next";
354-
console.log(button.accessibleNode.role); // null, not "button"
355-
console.log(button.accessibleNode.label); // null, not "Next"
356-
357-
button.setAttribute("role", "link");
358-
button.setAttribute("aria-label", "Next Page");
359-
console.log(button.accessibleNode.role); // null, not "link"
360-
console.log(button.accessibleNode.label); // null, not "Next Page"
367+
console.log(clickBtn.accessibleNode.role); // null, not "button"
361368
```
362369

363-
Similarly, setting Accessible Properties on an `AccessibleNode` does not
364-
affect corresponding ARIA attributes at all.
370+
And AOM does not reflect to ARIA:
365371

366-
```js
367-
button.accessibleNode.role = "menuitem";
368-
button.accessibleNode.label = "Next Page (Ctrl+N)";
369-
console.log(button.getAttribute("role")); // still "link"
370-
console.log(button.getAttribute("aria-label")); // still "Next Page"
372+
```html
373+
clickBtn.accessibleNode.role = "link";
374+
375+
console.log(clickBtn.getAttribute("role")); // Still "button"
371376
```
372377

373-
This is analogous to the `style` attribute, which allows
374-
reading and setting an element's local style, while
375-
`getComputedStyle()` allows access to the full computed style.
378+
##### ARIA takes precedence
379+
380+
In the case where and AOM Accessible Property and the corresponding ARIA attribute have different values,
381+
the ARIA attribute takes precedence.
376382

377-
Part of the reasoning behind this is that there are some cases in which
378-
Accessible Properties are more expressive than ARIA attributes - for example,
379-
referencing elements that don't have IDs. Since there would be no way to
380-
represent those cases as DOM attribute.
383+
For example, in the case in the previous section,
384+
`clickBtn` would have a computed role of `"button"`
385+
even though its `accessibleNode` has a `role` of `"link"`.
381386

382-
Another reason is for efficiency and tidiness: setting a DOM attribute is more
383-
heavyweight than setting a property of an object from JavaScript. Authors who
384-
are concerned about the performance of their web application or the bloated
385-
size of their generated HTML will find using the Accessibility Object Model
386-
to be a more efficient alternative. It also promotes creating custom elements
387-
that are clean and fully encapsulate their own accessibility rather than
388-
leaking it.
387+
##### Reasoning
388+
389+
The reasons for these decisions are discussed in #60,
390+
but in summary the benefits are:
391+
- Authors can use ARIA to modify elements which apply their own default Accessibility Properties,
392+
as in the case of Custom Elements;
393+
- ARIA is still a source of truth in the DOM tree;
394+
- There is no need to handle cases such as related nodes where Accessible Properties
395+
can express things which ARIA cannot;
396+
- Setting Accessible Properties will not have the performance implications
397+
of setting a DOM attribute.
389398

390399
#### Computed accessible properties
391400

392-
In Phase 4 the Accessibility Object Model spec will provide a way to get the computed
393-
value of accessibility properties.
401+
Accessible Properties explicitly **will not** allow authors to access
402+
the _computed_ accessible node properties corresponding to a given DOM node:
394403

395-
The reason this will be done via a separate mechanism is because the computed
396-
value of many accessible properties requires layout. Allowing web authors to query
397-
the computed value of an accessible property at any time via a simple property access
398-
would introduce confusing performance bottlenecks.
404+
```html
405+
<button id="composeBtn">Compose</button>
406+
```
407+
```js
408+
var composeBtn = document.getElementById('composeBtn');
409+
console.log(composeBtn.accessibleNode.role); // null, not "button"
410+
console.log(composeBtn.accessibleNode.label); // null, not "Compose"
411+
```
412+
413+
This is analogous to the `style` attribute,
414+
which allows reading and setting an element's local style,
415+
while `getComputedStyle()` allows access to the full computed style.
416+
417+
[Phase 4](#phase-4-full-introspection-of-an-accessibility-tree) will allow accessing the computed properties.
399418

400419
#### Validation
401420

402-
Querying an Accessible Property can be used as a limited
403-
form of validation and feature detection.
421+
Querying an Accessible Property can be used as a limited form of validation and feature detection.
404422

405-
On an uninitialized `AccessibleNode`, properties that are supported by the
406-
browser will return `null` initially, while unsupported / unrecognized
407-
properties return `undefined`:
423+
On an uninitialized `AccessibleNode`,
424+
properties that are supported by the browser will return `null` initially,
425+
while unsupported / unrecognized properties return `undefined`:
408426

409427
```js
410428
console.log(el.accessibleNode.role); // null
@@ -543,7 +561,7 @@ document.body.accessibleNode.removeChild(virtualNode);
543561

544562
In addition, calling appendChild on a node that's already inserted somewhere else
545563
in the accessibility tree will implicitly remove it from its old location and
546-
append it to the
564+
append it to the
547565

548566
Finally, the AOM also provides `insertChild` that's analogous to the DOM Node
549567
insertChild method, taking a zero-based index and then a child.
@@ -613,6 +631,34 @@ This will make it possible to:
613631
for example, detecting the exposed role of an element
614632
and modifying the accessible help text to suit.
615633

634+
#### Why is accessing the computed properties being addressed last?
635+
636+
**Consistency**
637+
Currently, the accessibility tree is not standardized between browsers:
638+
Each implements accessibility tree computation slightly differently.
639+
In order for this API to be useful,
640+
it needs to work consistently across browsers,
641+
so that developers don't need to write special case code for each.
642+
643+
We want to take the appropriate time to ensure we can agree
644+
on the details for how the tree should be computed
645+
and represented.
646+
647+
**Performance**
648+
Computing the value of many accessible properties requires layout.
649+
Allowing web authors to query the computed value of an accessible property
650+
synchronously via a simple property access
651+
would introduce confusing performance bottlenecks.
652+
653+
We will likely want to create an asynchronous mechanism for this reason,
654+
meaning that it will not be part of the `accessibleNode` interface.
655+
656+
**User experience**
657+
Compared to the previous three phases,
658+
accessing the computed accessibility tree will have the least direct impact on users.
659+
In the spirit of the [Priority of Constituencies](https://www.w3.org/TR/html-design-principles/#priority-of-constituencies),
660+
it makes sense to tackle this work last.
661+
616662
### Phases: Summary
617663

618664
![All phases of the AOM shown on the flow chart](images/DOM-a11y-tree-AOM.png)

0 commit comments

Comments
 (0)