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
Copy file name to clipboardExpand all lines: docs/rules/accessibility/no-aria-label-misuse.md
+37-7Lines changed: 37 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,32 +2,60 @@
2
2
3
3
## Rule Details
4
4
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`.
6
6
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!"
8
8
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
10
17
11
-
Also check out the following resources:
12
18
-[w3c/aria Consider prohibiting author naming certain roles #833](https://github.com/w3c/aria/issues/833)
13
19
-[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).
14
25
15
26
### 👎 Examples of **incorrect** code for this rule:
16
27
17
28
```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>
19
34
```
20
35
21
36
```erb
22
37
<div aria-labelledby="heading1">Goodbye</div>
23
38
```
24
39
25
40
```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>
0 commit comments