-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rule 2ee8b8 ("Visible label is part of accessible name"): introducing a new "label in name algorithm". #2075
base: develop
Are you sure you want to change the base?
Changes from 18 commits
aeafb90
5a07973
a75c7f8
623d26e
f920a47
ee3e993
75a9878
81caf8a
2928be6
5cd8b2c
092c849
f499d04
473bcb8
5c7fc1e
3d3b657
8ed61b8
24d0ffc
46294dd
a141df8
5220766
b2df021
cde4ad4
83d0e10
5dce8e1
2cfe5f8
7cdf8c3
563ff5e
53fe350
821de81
f9e7272
ae2273a
d4f8076
2dcd941
09f668c
a37cfd3
22ad17b
2dc429f
2ab4489
db37b3b
7b2a053
9723ed1
4da5300
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -23,6 +23,7 @@ acknowledgments: | |||||
authors: | ||||||
- Anne Thyme Nørregaard | ||||||
- Bryn Anderson | ||||||
- Dan Tripp | ||||||
- Jey Nandakumar | ||||||
funding: | ||||||
- WAI-Tools | ||||||
|
@@ -38,10 +39,14 @@ This rule applies to any element for which all the following is true: | |||||
|
||||||
## Expectation | ||||||
|
||||||
For each target element, all [text nodes][] in the [visible text content][] either match or are contained within the [accessible name][] of this target element, except for characters in the [text nodes][] used to express [non-text content][]. Leading and trailing [whitespace][] and difference in case sensitivity should be ignored. | ||||||
For the target element, the [visible inner text][] is contained within the [accessible name][] according to the [label in name algorithm][]. | ||||||
|
||||||
## Assumptions | ||||||
|
||||||
This rule assumes that the [visible inner text][] is equal to the [label][https://www.w3.org/WAI/WCAG21/Understanding/label-in-name#dfn-label] in most cases (enough cases to be useful) even though "label" is not precisely defined at this point in history. | ||||||
|
||||||
This rule assumes that neither the label nor the [visible inner text][] are rearranged with CSS in some way so that they appear to the user in a different order than they do in the DOM. | ||||||
|
||||||
This rule assumes that all resources needed for rendering the page are properly loaded. Checking if resources are missing is out of the scope of rules. Missing resources may be rendered as text (for example, missing `img` are rendered as their `alt` attribute). | ||||||
|
||||||
## Accessibility Support | ||||||
|
@@ -54,6 +59,7 @@ This rule applies to elements with a [widget role][] that [support name from con | |||||
|
||||||
The understanding document of [2.5.3 Label in Name][understand253] use the term "symbolic text characters" to refer to a type of [non-text content][] that uses text characters as symbols, such as using "x" to mean "close". This rule considers them as "characters expressing non-text content". Unicode emojis are another example of characters expressing non-text content, although these are not "symbolic text characters". | ||||||
|
||||||
|
||||||
### Bibliography | ||||||
|
||||||
- [Understanding Success Criterion 2.5.3: Label in Name][understand253] | ||||||
|
@@ -65,39 +71,39 @@ The understanding document of [2.5.3 Label in Name][understand253] use the term | |||||
|
||||||
#### Passed Example 1 | ||||||
|
||||||
This link has [visible][] text that matches the [accessible name][]. | ||||||
This link has [visible inner text][] that is equal to the [accessible name][]. | ||||||
|
||||||
```html | ||||||
<a href="https://act-rules.github.io/" aria-label="ACT rules">ACT rules</a> | ||||||
``` | ||||||
|
||||||
#### Passed Example 2 | ||||||
|
||||||
This link has [visible][] text that, ignoring trailing whitespace, matches the [accessible name][]. | ||||||
This link has [visible inner text][] that, ignoring whitespace, is equal to the [accessible name][]. | ||||||
|
||||||
```html | ||||||
<a href="https://act-rules.github.io/" aria-label=" ACT rules ">ACT rules</a> | ||||||
<a href="https://act-rules.github.io/" aria-label=" ACT rules ">ACT rules</a> | ||||||
``` | ||||||
|
||||||
#### Passed Example 3 | ||||||
|
||||||
This link has [visible][] text that, ignoring case, matches the [accessible name][]. | ||||||
This link has [visible inner text][] that, ignoring case, is equal to the [accessible name][]. | ||||||
|
||||||
```html | ||||||
<a href="https://act-rules.github.io/" aria-label="act rules">ACT rules</a> | ||||||
<a href="https://act-rules.github.io/" aria-label="act Rules">ACT rules</a> | ||||||
``` | ||||||
|
||||||
#### Passed Example 4 | ||||||
|
||||||
This button has [visible][] text that is contained within the [accessible name][]. | ||||||
This button has [visible inner text][] that is contained within the [accessible name][] according to the [label in name algorithm][]. | ||||||
|
||||||
```html | ||||||
<button aria-label="Next Page in the list">Next Page</button> | ||||||
``` | ||||||
|
||||||
#### Passed Example 5 | ||||||
|
||||||
This button has [visible][] text that does not need to be contained within the [accessible name][], because the "x" text node is [non-text content][]. | ||||||
The "X" is [non-text content][], so it doesn't need to be contained within the [accessible name][]. | ||||||
|
||||||
```html | ||||||
<button aria-label="close">X</button> | ||||||
|
@@ -117,45 +123,253 @@ This `button` element has the text "search" rendered as an magnifying glass icon | |||||
<button aria-label="Find">search</button> | ||||||
``` | ||||||
|
||||||
#### Passed Example 7 | ||||||
|
||||||
This button has [visible inner text][] that, according to the [label in name algorithm][], is contained within the [accessible name][]. This example shows why the [label in name algorithm][] uses the [visible inner text][] and not the [visible text content][]: the <p> tags insert whitespace into the result in the former but not the latter. | ||||||
|
||||||
```html | ||||||
<button aria-label="Hello world"><p>Hello</p><p>world</p></button> | ||||||
``` | ||||||
|
||||||
#### Passed Example 8 | ||||||
|
||||||
Similar to the previous example. | ||||||
|
||||||
```html | ||||||
<a href="#" aria-label="Some article by John Doe"><h6>Some article</h6><p>by John Doe</p></a> | ||||||
``` | ||||||
|
||||||
#### Passed Example 9 | ||||||
|
||||||
The [visible inner text][] of this link is "ACT" (with no spaces) because of the explicit styles of "display: inline" on the <p> elements and the absence of whitespace between the <p> elements. The cases of "display: inline" and "display: block" are handled by the definition of [visible inner text of an element][]. This example shows that the definition agrees with the visual rendering done by the browser. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in 2dcd941. |
||||||
|
||||||
```html | ||||||
<a href="#" aria-label="ACT"> | ||||||
<p style="display: inline">A</p><p style="display: inline">C</p><p style="display: inline">T</p> | ||||||
</a> | ||||||
``` | ||||||
|
||||||
#### Passed Example 10 | ||||||
|
||||||
The [visible inner text][] is "Download specification". The words "the" and "gizmo" aren't part of it. | ||||||
|
||||||
```html | ||||||
<a aria-label="Download specification" href="#">Download <span style="visibility: hidden">the</span> <span style="display: none">gizmo</span> specification</a> | ||||||
``` | ||||||
|
||||||
#### Passed Example 11 | ||||||
|
||||||
The [visible inner text][] is "Download specification", which includes a space character between the two words due to the second clause of the definition of [visible inner text of a text node][]. | ||||||
|
||||||
```html | ||||||
<a aria-label="Download specification" href="#"><span>Download</span><span id="space"> </span><span>specification</span></a> | ||||||
``` | ||||||
|
||||||
#### Passed Example 12 | ||||||
|
||||||
This example shows that the [visible inner text][] isn't always the same as the [innerText][https://html.spec.whatwg.org/multipage/dom.html#the-innertext-idl-attribute]. The visible inner text is "Download specification". The innerText is 'Download \ngizmo\nspecification'. This rule uses the visible inner text - not innerText. | ||||||
|
||||||
```html | ||||||
<style> | ||||||
.visually-hidden { | ||||||
/* Source: https://www.tpgi.com/the-anatomy-of-visually-hidden/ */ | ||||||
clip-path: inset(50%); | ||||||
height: 1px; | ||||||
overflow: hidden; | ||||||
position: absolute; | ||||||
white-space: nowrap; | ||||||
width: 1px; | ||||||
} | ||||||
</style> | ||||||
<a aria-label="Download specification" href="#">Download <span class="visually-hidden">gizmo</span> specification</a> | ||||||
``` | ||||||
|
||||||
#### Passed Example 13 | ||||||
|
||||||
This example shows that the [label in name algorithm][] handles many kinds of whitespace. | ||||||
|
||||||
```html | ||||||
<a aria-label="compose email" href="#">compose <br> email</a> | ||||||
``` | ||||||
|
||||||
#### Passed Example 14 | ||||||
|
||||||
This example passes the rule because "YYYY-MM-DD" is in brackets. Text in brackets is removed by the [label in name algorithm][], because its not normally spoken by speech-input users. | ||||||
|
||||||
```html | ||||||
<button aria-label="Search by date">Search by date (YYYY-MM-DD)</button> | ||||||
``` | ||||||
|
||||||
#### Passed Example 15 | ||||||
|
||||||
The passes for two reasons: 1) because the ellipsis ("…") is [non-text content][], and 2) because the ellipsis is neither a letter nor a digit and so is filtered out by the [label in name algorithm][]. | ||||||
|
||||||
```html | ||||||
<button aria-label="Next">Next…</button> | ||||||
``` | ||||||
|
||||||
#### Passed Example 16 | ||||||
|
||||||
This passes because the [label in name algorithm][] effectively ignores all punctuation and emoji, in both the visible inner text and the accessible name, as long as they don't break up words. | ||||||
|
||||||
```html | ||||||
<button aria-label="💡 Submit 💡">>>> ** Submit ** <<<</button> | ||||||
``` | ||||||
|
||||||
|
||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think adding the "First Name:" pass example from the Understanding document would be useful (since it's very common). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a strong example for the SC, but I can't see how to adapt it to this ACT rule. That example ( |
||||||
|
||||||
|
||||||
### Failed | ||||||
|
||||||
#### Failed Example 1 | ||||||
|
||||||
This link has [visible][] text that is different from the [accessible name][]. | ||||||
This link has [visible inner text][] that is very different from the [accessible name][]. | ||||||
|
||||||
```html | ||||||
<a href="https://act-rules.github.io/" aria-label="WCAG">ACT rules</a> | ||||||
``` | ||||||
|
||||||
#### Failed Example 2 | ||||||
|
||||||
This button has [visible][] text that is only partially contained within the [accessible name][]. | ||||||
This button has [visible inner text][] that is only partially contained within the [accessible name][]. | ||||||
|
||||||
```html | ||||||
<button aria-label="the full">The full label</button> | ||||||
``` | ||||||
|
||||||
#### Failed Example 3 | ||||||
#### Failed Example 3 | ||||||
|
||||||
This button has [visible inner text][] that is fully contained within the [accessible name][] when viewed as a character-by-character substring. But that does not satisfy our [label in name algorithm][], which works on full words. So this fails the rule. | ||||||
|
||||||
```html | ||||||
<a href="#" aria-label="Discover Italy">Discover It</a> | ||||||
``` | ||||||
|
||||||
#### Failed Example 4 | ||||||
|
||||||
This link has [visible][] text with mathematical symbols, that does not match the [accessible name][] because the mathematical symbols were written out in the accessible name. This is [explicitly mentioned in WCAG](https://www.w3.org/WAI/WCAG21/Understanding/label-in-name#mathematical-expressions-and-formulae). | ||||||
This link's [accessible name][] contains two tokens (according to the[label in name algorithm][]) and the [visible inner text][] contains one token. So it fails the rule. | ||||||
|
||||||
```html | ||||||
<a aria-label="just ice" href="#">justice</a> | ||||||
``` | ||||||
|
||||||
#### Failed Example 5 | ||||||
|
||||||
This link has an [accessible name][] which contains a hyphen. The [label in name algorithm][] breaks up words on hyphens. So it turns "non-standard" into two tokens: "non" and "standard". So this fails the rule. | ||||||
|
||||||
```html | ||||||
<a href="#" aria-label="non-standard">nonstandard</a> | ||||||
``` | ||||||
|
||||||
#### Failed Example 6 | ||||||
|
||||||
The rule has no special handling for acronyms or initialisms. | ||||||
|
||||||
```html | ||||||
<a aria-label="WCAG" href="#">W C A G</a> | ||||||
``` | ||||||
|
||||||
#### Failed Example 7 | ||||||
|
||||||
The rule has no special handling for abbreviations. | ||||||
|
||||||
```html | ||||||
<a aria-label="University Avenue" href="#">University Ave.</a> | ||||||
``` | ||||||
|
||||||
#### Failed Example 8 | ||||||
|
||||||
This link has [visible inner text][] with mathematical symbols and is not contained within the [accessible name][] because the mathematical symbols are represented as English words (not digits) in the accessible name. This is [explicitly mentioned in WCAG](https://www.w3.org/WAI/WCAG21/Understanding/label-in-name#mathematical-expressions-and-formulae). | ||||||
|
||||||
```html | ||||||
<a href="/" aria-label="Proof of two multiplied by two is four">Proof of 2×2=4</a> | ||||||
``` | ||||||
|
||||||
#### Failed Example 9 | ||||||
|
||||||
Similar to the previous example. This rule has no special handling for converting mathematical symbols into words, or vice versa. | ||||||
|
||||||
```html | ||||||
<button aria-label="11 times 3 equals 33">11×3=33</button> | ||||||
``` | ||||||
|
||||||
#### Failed Example 10 | ||||||
|
||||||
This button's accessible name contains the same tokens that are in the visible label. But they aren't in the same order, so it fails the sublist check part of the [label in name algorithm][], and so it fails the rule. | ||||||
|
||||||
```html | ||||||
<button aria-label="how are you"><span>you</span><span>how</span><span>are</span></button> | ||||||
``` | ||||||
|
||||||
#### Failed Example 11 | ||||||
|
||||||
This link's accessible name contains the same digits that are in the visible label, and in the same order. But they have different spaces and punctuation between them, so they are considered separate tokens. So this fails the rule. | ||||||
|
||||||
```html | ||||||
<a aria-label="Call 1 2 3. 4 5 6. 7 8 9 0." href="tel:1234567890">123.456.7890</a> | ||||||
``` | ||||||
|
||||||
#### Failed Example 12 | ||||||
|
||||||
This rule has no special handling which tries to guess when number have the same semantic meaning. It operates on tokens only. | ||||||
|
||||||
```html | ||||||
<a href="#2021" aria-label="20 21">2021</a> | ||||||
``` | ||||||
|
||||||
#### Failed Example 13 | ||||||
|
||||||
Similar to the previous example. | ||||||
|
||||||
```html | ||||||
<a aria-label="fibonacci: 0 1 1 2 3 5 8 13 21 34">fibonacci: 0112358132134</a> | ||||||
``` | ||||||
|
||||||
#### Failed Example 14 | ||||||
|
||||||
This rule has no special handling for converting digits into words, or vice versa. | ||||||
|
||||||
```html | ||||||
<a href="#2021" aria-label="twenty twenty-one">two thousand twenty-one</a> | ||||||
``` | ||||||
|
||||||
#### Failed Example 15 | ||||||
|
||||||
(Same as above.) This rule has no special handling for converting digits into words, or vice versa. | ||||||
|
||||||
```html | ||||||
<a aria-label="two zero two three" href="#">2 0 2 3</a> | ||||||
``` | ||||||
|
||||||
#### Failed Example 16 | ||||||
|
||||||
This rule has no special handling for digits that appear next to letters with no spaces in between. | ||||||
|
||||||
```html | ||||||
<a aria-label="1a" href="#">1</a> | ||||||
``` | ||||||
|
||||||
#### Failed Example 17 | ||||||
|
||||||
The definition of [visible inner text][] doesn't treat text any differently if it's excluded from the accessibility tree with aria-hidden. So this rule effectively ignores aria-hidden. So this element fails the rule. | ||||||
|
||||||
```html | ||||||
<a aria-label="Download specification" href="#">Download <span aria-hidden="true">gizmo</span> specification</a> | ||||||
``` | ||||||
|
||||||
### Inapplicable | ||||||
|
||||||
#### Inapplicable Example 1 | ||||||
|
||||||
This `nav` is not a widget, so the [visible][] text does not need to match the [accessible name][]. | ||||||
This `nav` is not a widget, so the [visible inner text][] does not need to match the [accessible name][]. | ||||||
|
||||||
```html | ||||||
<nav aria-label="main nav">W3C navigation</nav> | ||||||
``` | ||||||
|
||||||
#### Inapplicable Example 2 | ||||||
|
||||||
This email text field does not need to have its [visible][] text match the [accessible name][]. The content of a textfield shows its value instead of its label; it does not [support name from content][supports name from content]. The label is usually adjacent to the textfield instead. | ||||||
This email text field does not need to have its [visible inner text][] match the [accessible name][]. The content of a textfield shows its value instead of its label; it does not [support name from content][supports name from content]. The label is usually adjacent to the textfield instead. | ||||||
|
||||||
```html | ||||||
<div>E-mail</div> | ||||||
|
@@ -164,15 +378,15 @@ This email text field does not need to have its [visible][] text match the [acce | |||||
|
||||||
#### Inapplicable Example 3 | ||||||
|
||||||
This `div` element does not have a widget role, so the [visible][] text does not need to match the [accessible name][]. | ||||||
This `div` element does not have a widget role, so the [visible inner text][]t does not need to match the [accessible name][]. | ||||||
|
||||||
```html | ||||||
<div role="tooltip" aria-label="OK">Next</div> | ||||||
``` | ||||||
|
||||||
#### Inapplicable Example 4 | ||||||
|
||||||
This link has no [visible text content][]. | ||||||
This link has no [visible inner text][]. | ||||||
|
||||||
```html | ||||||
<a href="https://w3.org" aria-label="W3C homepage"> | ||||||
|
@@ -186,6 +400,9 @@ This link has no [visible text content][]. | |||||
[semantic role]: #semantic-role 'Definition of Semantic role' | ||||||
[supports name from content]: https://www.w3.org/TR/wai-aria-1.1/#namefromcontent 'Definition of Supports name from contents' | ||||||
[visible]: #visible 'Definition of visible' | ||||||
[visible inner text]: #visible-inner-text 'Definition of Visible inner text' | ||||||
[visible inner text of a text node]: #visible-inner-text:for-text 'Definition of Visible inner text of a text node' | ||||||
[visible inner text of an element]: #visible-inner-text:for-element 'Definition of Visible inner text of an element' | ||||||
[visible text content]: #visible-text-content 'Definition of Visible text content' | ||||||
[whitespace]: #whitespace 'Definition of Whitespace' | ||||||
[widget role]: https://www.w3.org/TR/wai-aria-1.1/#widget_roles 'Definition of Widget role' | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Referencing "previous example" is a bit risky since nothing guarantees they will stay in the same order next time we rewrite the rule.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree there is a risk. In this case I think that the risk is worth it. With "previous", I claim that the readability is improved now. If I remove "previous", I can't think of a way to rewrite it that doesn't make it significantly less readable.