Skip to content

Commit

Permalink
Add to .md and move up validRoles as a Set
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Goldberg committed Dec 3, 2021
1 parent f869a74 commit 77f6c87
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/rules/aria-role.md
Expand Up @@ -17,7 +17,7 @@ This rule takes one optional object argument of type object:
}
```

`allowedInvalidRules` is an optional string array of custom roles that should be allowed in addition to the ARIA spec.
`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).

For the `ignoreNonDOM` option, this determines if developer created components are checked.

Expand Down
2 changes: 1 addition & 1 deletion src/rules/aria-role.js
Expand Up @@ -39,6 +39,7 @@ export default {
const options = context.options[0] || {};
const ignoreNonDOM = !!options.ignoreNonDOM;
const allowedInvalidRoles = new Set(options.allowedInvalidRoles || [])
const validRoles = [...roles.keys()].filter((role) => roles.get(role).abstract === false);

return ({
JSXAttribute: (attribute) => {
Expand All @@ -63,7 +64,6 @@ export default {
if (value === undefined || value === null) { return; }

const values = String(value).split(' ');
const validRoles = [...roles.keys()].filter((role) => roles.get(role).abstract === false);
const isValid = values.every((val) => allowedInvalidRoles.has(val) || validRoles.indexOf(val) > -1);

if (isValid === true) { return; }
Expand Down

0 comments on commit 77f6c87

Please sign in to comment.