| 1 | # jsx-a11y/aria-role
|
|---|
| 2 |
|
|---|
| 3 | 💼 This rule is enabled in the following configs: ☑️ `recommended`, 🔒 `strict`.
|
|---|
| 4 |
|
|---|
| 5 | <!-- end auto-generated rule header -->
|
|---|
| 6 |
|
|---|
| 7 | Elements with ARIA roles must use a valid, non-abstract ARIA role. A reference to role definitions can be found at [WAI-ARIA](https://www.w3.org/TR/wai-aria/#role_definitions) site.
|
|---|
| 8 |
|
|---|
| 9 | ## Rule options
|
|---|
| 10 |
|
|---|
| 11 | This rule takes one optional object argument of type object:
|
|---|
| 12 |
|
|---|
| 13 | ```json
|
|---|
| 14 | {
|
|---|
| 15 | "rules": {
|
|---|
| 16 | "jsx-a11y/aria-role": [ 2, {
|
|---|
| 17 | "allowedInvalidRoles": ["text"],
|
|---|
| 18 | "ignoreNonDOM": true
|
|---|
| 19 | }],
|
|---|
| 20 | }
|
|---|
| 21 | }
|
|---|
| 22 | ```
|
|---|
| 23 |
|
|---|
| 24 | `allowedInvalidRules` is an optional string array of custom roles that should be allowed in addition to the ARIA spec, such as for cases when you [need to use a non-standard role](https://axesslab.com/text-splitting).
|
|---|
| 25 |
|
|---|
| 26 | For the `ignoreNonDOM` option, this determines if developer created components are checked.
|
|---|
| 27 |
|
|---|
| 28 | ### Succeed
|
|---|
| 29 | ```jsx
|
|---|
| 30 | <div role="button"></div> <!-- Good: "button" is a valid ARIA role -->
|
|---|
| 31 | <div role={role}></div> <!-- Good: role is a variable & cannot be determined until runtime. -->
|
|---|
| 32 | <div></div> <!-- Good: No ARIA role -->
|
|---|
| 33 | <Foo role={role}></Foo> <!-- Good: ignoreNonDOM is set to true -->
|
|---|
| 34 | ```
|
|---|
| 35 |
|
|---|
| 36 | ### Fail
|
|---|
| 37 |
|
|---|
| 38 | ```jsx
|
|---|
| 39 | <div role="datepicker"></div> <!-- Bad: "datepicker" is not an ARIA role -->
|
|---|
| 40 | <div role="range"></div> <!-- Bad: "range" is an _abstract_ ARIA role -->
|
|---|
| 41 | <div role=""></div> <!-- Bad: An empty ARIA role is not allowed -->
|
|---|
| 42 | <Foo role={role}></Foo> <!-- Bad: ignoreNonDOM is set to false or not set -->
|
|---|
| 43 | ```
|
|---|
| 44 |
|
|---|
| 45 | ## Accessibility guidelines
|
|---|
| 46 | - [WCAG 4.1.2](https://www.w3.org/WAI/WCAG21/Understanding/name-role-value)
|
|---|
| 47 |
|
|---|
| 48 | ### Resources
|
|---|
| 49 | - [Chrome Audit Rules, AX_ARIA_01](https://github.com/GoogleChrome/accessibility-developer-tools/wiki/Audit-Rules#ax_aria_01)
|
|---|
| 50 | - [DPUB-ARIA roles](https://www.w3.org/TR/dpub-aria-1.0/)
|
|---|
| 51 | - [MDN: Using ARIA: Roles, states, and properties](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques)
|
|---|