|
| 1 | +# Role Supports ARIA Props |
| 2 | + |
| 3 | +## Rule Details |
| 4 | + |
| 5 | +This rule enforces that elements with explicit or implicit roles defined contain only `aria-*` properties supported by that `role`. |
| 6 | + |
| 7 | +For example, 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`. |
| 8 | + |
| 9 | +### "Help! I'm trying to set a tooltip on a static element and this rule flagged it!" |
| 10 | + |
| 11 | +Please do not use tooltips on static elements. It is a highly discouraged, inaccessible pattern. |
| 12 | +See [Primer: Tooltip alternatives](https://primer.style/design/accessibility/tooltip-alternatives) for what to do instead. |
| 13 | + |
| 14 | +### Resources |
| 15 | + |
| 16 | +- [w3c/aria Consider prohibiting author naming certain roles #833](https://github.com/w3c/aria/issues/833) |
| 17 | +- [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/) |
| 18 | +- [Your tooltips are bogus](https://heydonworks.com/article/your-tooltips-are-bogus/) |
| 19 | +- [Primer: Tooltip alternatives](https://primer.style/design/accessibility/tooltip-alternatives) |
| 20 | + |
| 21 | +### Disclaimer |
| 22 | + |
| 23 | +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). |
| 24 | + |
| 25 | +### **Incorrect** code for this rule 👎 |
| 26 | + |
| 27 | +```erb |
| 28 | +<span class="tooltipped" aria-label="This is a tooltip">I am some text.</span> |
| 29 | +``` |
| 30 | + |
| 31 | +```erb |
| 32 | +<span aria-label="This is some content that will completely override the button content">Please be careful of the following.</span> |
| 33 | +``` |
| 34 | + |
| 35 | +```erb |
| 36 | +<div aria-labelledby="heading1">Goodbye</div> |
| 37 | +``` |
| 38 | + |
| 39 | +```erb |
| 40 | +<h1 aria-label="This will override the page title completely">Page title</h1> |
| 41 | +``` |
| 42 | + |
| 43 | +### **Correct** code for this rule 👍 |
| 44 | + |
| 45 | +```erb |
| 46 | +<button aria-label="Close"> |
| 47 | + <svg src="closeIcon"></svg> |
| 48 | +</button> |
| 49 | +``` |
| 50 | + |
| 51 | +```erb |
| 52 | +<button aria-label="Bold" aria-describedby="tooltip1"> |
| 53 | + <svg src="boldIcon"></svg> |
| 54 | +</button> |
| 55 | +<p id="tooltip1" class="tooltip">Add bold text or turn selection into bold text</p> |
| 56 | +``` |
| 57 | + |
| 58 | +```erb |
| 59 | +<span>Hello</span> |
| 60 | +``` |
| 61 | + |
| 62 | +```erb |
| 63 | +<div>Goodbye</div> |
| 64 | +``` |
| 65 | + |
| 66 | +```erb |
| 67 | +<h1>Page title</h1> |
| 68 | +``` |
| 69 | + |
| 70 | +```erb |
| 71 | +<div role="dialog" aria-labelledby="dialogHeading"> |
| 72 | + <h1 id="dialogHeading">Heading</h1> |
| 73 | +</div> |
| 74 | +``` |
0 commit comments