You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -38,10 +39,14 @@ This rule applies to any element for which all the following is true:
38
39
39
40
## Expectation
40
41
41
-
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.
42
+
For each target element, the [visible inner text][]is contained within the [accessible name][] of the target element according to the [label in name algorithm][].
42
43
43
44
## Assumptions
44
45
46
+
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.
47
+
48
+
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.
49
+
45
50
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).
46
51
47
52
## Accessibility Support
@@ -54,6 +59,7 @@ This rule applies to elements with a [widget role][] that [support name from con
54
59
55
60
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".
56
61
62
+
57
63
### Bibliography
58
64
59
65
-[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
65
71
66
72
#### Passed Example 1
67
73
68
-
This link has [visible][]text that matches the [accessible name][].
74
+
This link has [visible inner text][] that is equal to the [accessible name][].
This button has [visible][]text that is contained within the [accessible name][].
98
+
This button has [visible inner text][] that is contained within the [accessible name][] according to the [label in name algorithm][].
93
99
94
100
```html
95
101
<buttonaria-label="Next Page in the list">Next Page</button>
96
102
```
97
103
98
104
#### Passed Example 5
99
105
100
-
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][].
106
+
The "X" is [non-text content][], so it doesn't need to be contained within the [accessible name][].
101
107
102
108
```html
103
109
<buttonaria-label="close">X</button>
@@ -117,45 +123,242 @@ This `button` element has the text "search" rendered as an magnifying glass icon
117
123
<buttonaria-label="Find">search</button>
118
124
```
119
125
126
+
#### Passed Example 7
127
+
128
+
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.
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.
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.
180
+
181
+
```html
182
+
<buttonaria-label="Search by date">Search by date (YYYY-MM-DD)</button>
183
+
```
184
+
185
+
#### Passed Example 13
186
+
187
+
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][].
188
+
189
+
```html
190
+
<buttonaria-label="Next">Next…</button>
191
+
```
192
+
193
+
#### Passed Example 14
194
+
195
+
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.
This button has [visible][] text that is only partially contained within the [accessible name][].
223
+
This button has [visible inner text][] that is only partially contained within the [accessible name][].
133
224
134
225
```html
135
226
<buttonaria-label="the full">The full label</button>
136
227
```
137
228
138
-
#### Failed Example 3
229
+
#### Failed Example 3
230
+
231
+
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.
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.
240
+
241
+
```html
242
+
<aaria-label="just ice"href="#">justice</a>
243
+
```
244
+
245
+
#### Failed Example 5
246
+
247
+
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.
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).
271
+
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).
141
272
142
273
```html
143
274
<ahref="/"aria-label="Proof of two multiplied by two is four">Proof of 2×2=4</a>
144
275
```
145
276
277
+
#### Failed Example 9
278
+
279
+
Similar to the previous example. This rule has no special handling for converting mathematical symbols into words, or vice versa.
280
+
281
+
```html
282
+
<buttonaria-label="11 times 3 equals 33">11×3=33</button>
283
+
```
284
+
285
+
#### Failed Example 10
286
+
287
+
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.
288
+
289
+
```html
290
+
<buttonaria-label="how are you"><span>you</span><span>how</span><span>are</span></button>
291
+
```
292
+
293
+
#### Failed Example 11
294
+
295
+
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.
(Same as above.) This rule has no special handling for converting digits into words, or vice versa.
328
+
329
+
```html
330
+
<aaria-label="two zero two three"href="#">2 0 2 3</a>
331
+
```
332
+
333
+
#### Failed Example 16
334
+
335
+
This rule has no special handling for digits that appear next to letters with no spaces in between.
336
+
337
+
```html
338
+
<aaria-label="1a"href="#">1</a>
339
+
```
340
+
341
+
#### Failed Example 17
342
+
343
+
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.
This `nav` is not a widget, so the [visible][] text does not need to match the [accessible name][].
353
+
This `nav` is not a widget, so the [visible inner text][] does not need to match the [accessible name][].
151
354
152
355
```html
153
356
<navaria-label="main nav">W3C navigation</nav>
154
357
```
155
358
156
359
#### Inapplicable Example 2
157
360
158
-
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.
361
+
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.
159
362
160
363
```html
161
364
<div>E-mail</div>
@@ -164,15 +367,15 @@ This email text field does not need to have its [visible][] text match the [acce
164
367
165
368
#### Inapplicable Example 3
166
369
167
-
This `div` element does not have a widget role, so the [visible][] text does not need to match the [accessible name][].
370
+
This `div` element does not have a widget role, so the [visible inner text][]t does not need to match the [accessible name][].
168
371
169
372
```html
170
373
<divrole="tooltip"aria-label="OK">Next</div>
171
374
```
172
375
173
376
#### Inapplicable Example 4
174
377
175
-
This link has no [visible text content][].
378
+
This link has no [visible inner text][].
176
379
177
380
```html
178
381
<ahref="https://w3.org"aria-label="W3C homepage">
@@ -186,6 +389,7 @@ This link has no [visible text content][].
186
389
[semantic role]: #semantic-role'Definition of Semantic role'
187
390
[supports name from content]: https://www.w3.org/TR/wai-aria-1.1/#namefromcontent'Definition of Supports name from contents'
188
391
[visible]: #visible'Definition of visible'
392
+
[visible inner text]: #visible-inner-text'Definition of Visible inner text'
189
393
[visible text content]: #visible-text-content'Definition of Visible text content'
190
394
[whitespace]: #whitespace'Definition of Whitespace'
191
395
[widget role]: https://www.w3.org/TR/wai-aria-1.1/#widget_roles'Definition of Widget role'
Let 'label' be the [visible inner text][] of the target element. Let 'name' be the [accessible name][] of the target element. Both 'label' and 'name' are strings.
12
+
13
+
Sub-algorithm to tokenize a string:
14
+
15
+
- Convert the string to lower case.
16
+
- For each character that either a) represents non-text content, or b) isn't a letter or a digit: replace that character with a space character.
17
+
- For a) Judgement of "non-text" probably can't be fully automated. eg. "X" for "close" probably can be, but presumably there are more cases than this.
18
+
- For b) Use the unicode classes Letter, Mark, and "Number, Decimal Digit [Nd]". (This will exclude hyphens, punctuation, emoji, and more.)
19
+
- Remove all characters that are within parentheses (AKA round brackets).
20
+
- Ignore square brackets and braces.
21
+
- Split the string into a list of strings, using a whitespace regular expression as the separator.
22
+
- This 'split' operation must:
23
+
- Effectively remove leading and trailing whitespace as a pre-processing step.
24
+
- If the string was all whitespace before this operation: result in an empty list.
25
+
26
+
Then do the check: is the tokenized 'label' a sublist of the tokenized 'name'?
27
+
- This 'sublist' check has these properties:
28
+
- It checks whether elements are consecutive or not. i.e. it checks for a substring, in the computer science sense of the term. Not a subsequence.
29
+
- An empty list is a sublist of any list.
30
+
31
+
If the answer is "yes" (i.e. the tokenized 'label' a sublist of the tokenized 'name'), then the target element passes the rule. Otherwise, it fails the rule.
32
+
33
+
[accessible name]: #accessible-name'Definition of accessible name'
34
+
[visible inner text]: #visible-inner-text'Definition of Visible inner text'
0 commit comments