[New] add isInteractiveRole helper util, see #601#602
Conversation
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. |
53ba5b1 to
f08b489
Compare
| const OVERRIDE_NON_INTERACTIVE: Set<string> = new Set(['progressbar']); | ||
|
|
||
| // Roles that are not widget descendants but do accept user input in practice. | ||
| const interactiveRoles: Set<string> = new Set(['toolbar']); |
There was a problem hiding this comment.
There was a problem hiding this comment.
it's actually more of a "Setlike" - see
aria-query/src/elementRoleMap.js
Lines 53 to 85 in c151daf
| } | ||
|
|
||
| export default function isInteractiveRole(role: string): boolean { | ||
| return interactiveRoles.indexOf(role) !== -1; |
There was a problem hiding this comment.
it'd probably be more performant to build up a null object, rather than an array?
There was a problem hiding this comment.
okay, thanks – addressed now.
Went with a plain {} (rather than Object.create(null) to avoid FlowIgnore or cast as any ((Flow seemed to reject Object.create(null) against { [string]: true }). But happy to switch to Object.create(null) with a suppression or cast if that is preferred.
There was a problem hiding this comment.
{ __proto__: null } is always better than Object.create(null), fwiw.
There was a problem hiding this comment.
okay, changed to '{ proto: null }' now.
d8d7538 to
b7029e4
Compare
See #601
Implements a helper util for the query "Is this role interactive?" — filter concrete roles whose superClass chain includes widget.
Inspired by eslint-plugins independently implementing the same
superClass.some(chain => chain.includes('widget'))loop. Three of them (angular-eslint, lit-a11y, eslint-plugin-ember) also independently arrived at the same two special cases: excludeprogressbar(its value is always readonly), includetoolbar(supportsaria-activedescendantin practice):src/util/isInteractiveRole.jslib/utils/interactive-roles.js(in review)src/utils/getInteractiveRoles.tsget-interactive-element-role-schemas.tslib/utils/isInteractiveElement.js