Skip to content

Commit 3c343fc

Browse files
committed
update rule description
1 parent 4f14ca1 commit 3c343fc

File tree

1 file changed

+37
-7
lines changed

1 file changed

+37
-7
lines changed

docs/rules/accessibility/no-aria-label-misuse.md

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,60 @@
22

33
## Rule Details
44

5-
This rule aims to minimize misuse of the `aria-label` and `aria-labelledby` attributes because the usage of these attributes is only guaranteed on interactive elements and a subset of ARIA roles. W3C provides [a list of ARIA roles which cannot be named](https://w3c.github.io/aria/#namefromprohibited) which is used as a basis for this linter.
5+
This rule aims to discourage common misuse of the `aria-label` and `aria-labelledby` attribute. `aria-label` and `aria-labelledby` support is only guaranteed on interactive elements like `button` or `a`, or on static elements like `div` and `span` with a permitted `role`. This rule will allow `aria-label` and `aria-labelledby` usage on `div` and `span` elements if it set to a role other than the ones listed in [WSC: a list of ARIA roles which cannot be named](https://w3c.github.io/aria/#namefromprohibited). This rule will never permit usage of `aria-label` and `aria-labelledby` on `h1`, `h2`, `h3`, `h4`, `h5`, `h6`, `strong`, `i`, `p`, `b`, or `code`.
66

7-
There are conflicting resources on what elements should support these naming attributes. For now, this rule will operate under a relatively simple heuristic aimed to minimize false positives, but has room for future improvements.
7+
### "Help! I'm trying to set a tooltip on a static element and this rule flagged it!"
88

9-
Learn more at [W3C Name Calcluation](https://w3c.github.io/aria/#namecalculation).
9+
Please do not use tooltips on static elements. It is a highly discouraged, inaccessible pattern for the following reasons:
10+
11+
- Static elements are not tab-focusable so keyboard-only users will not be able to access the tooltip at all. (Note: setting `tabindex="0"` to force a generic element to be focusable is not a solution.)
12+
- It's likely that tooltip is inappropriate for your usecase to begin with. Tooltips are not accessible at all on mobile devices so if you're trying to convey critical information, use something else. Additionally, implementing tooltip as `aria-label` is rarely appropriate and has potential to cause accessibility issues for screen reader users.
13+
14+
If you've determined the tooltip content is not critical, simply remove it. If you determine the tooltip content is important to keep, we encourage you to reach out to a design or accessibility team who can assist in finding an alternate, non-tooltip pattern.
15+
16+
### Resources
1017

11-
Also check out the following resources:
1218
- [w3c/aria Consider prohibiting author naming certain roles #833](https://github.com/w3c/aria/issues/833)
1319
- [Not so short note on aria-label usage - Big Table Edition](https://html5accessibility.com/stuff/2020/11/07/not-so-short-note-on-aria-label-usage-big-table-edition/)
20+
- [Your tooltips are bogus](https://heydonworks.com/article/your-tooltips-are-bogus/)
21+
22+
### Disclaimer
23+
24+
There are conflicting resources and opinions on what elements should support these naming attributes. For now, this rule will operate under a relatively simple heuristic aimed to minimize false positives. This may have room for future improvements. Learn more at [W3C Name Calcluation](https://w3c.github.io/aria/#namecalculation).
1425

1526
### 👎 Examples of **incorrect** code for this rule:
1627

1728
```erb
18-
<span aria-label="This does something">Hello</span>
29+
<span class="tooltipped" aria-label="This is a tooltip">I am some text.</span>
30+
```
31+
32+
```erb
33+
<span aria-label="This is some content that will completely override the button content">Please be careful of the following.</span>
1934
```
2035

2136
```erb
2237
<div aria-labelledby="heading1">Goodbye</div>
2338
```
2439

2540
```erb
26-
<h1 aria-label="This will override the content">Page title</h1>
41+
<h1 aria-label="This will override the page title completely">Page title</h1>
2742
```
2843

2944
### 👍 Examples of **correct** code for this rule:
3045

46+
```erb
47+
<button aria-label="Close">
48+
<svg src="closeIcon"></svg>
49+
</button>
50+
```
51+
52+
```erb
53+
<button aria-label="Bold" aria-describedby="tooltip1">
54+
<svg src="boldIcon"></svg>
55+
</button>
56+
<p id="tooltip1" class="tooltip">Add bold text or turn selection into bold text</p>
57+
```
58+
3159
```erb
3260
<span>Hello</span>
3361
```
@@ -41,5 +69,7 @@ Also check out the following resources:
4169
```
4270

4371
```erb
44-
<div role="dialog" aria-labelledby="dialogHeading"></div>
72+
<div role="dialog" aria-labelledby="dialogHeading">
73+
<h1 id="dialogHeading">Heading</h1>
74+
</div>
4575
```

0 commit comments

Comments
 (0)