UNPKG

@jsxtools/eslint-plugin-jsx-a11y

Version:

Static AST checker for accessibility rules on JSX elements for flat ESLint Config.

22 lines (19 loc) 826 B
import { roles, dom } from 'aria-query'; import { getLiteralPropValue, getProp } from './module/jsx-ast-utils.js'; const nonInteractiveRoles = [...roles.keys()].filter((name) => !roles.get(name).abstract && !roles.get(name).superClass.some((klasses) => klasses.includes("widget"))); const isNonInteractiveRole = (tagName, attributes) => { if (!dom.has(tagName)) { return false; } const role = getLiteralPropValue(getProp(attributes, "role")); let isNonInteractive = false; const normalizedValues = String(role).toLowerCase().split(" "); const validRoles = normalizedValues.flatMap( (name) => roles.has(name) ? [name] : [] ); if (validRoles.length > 0) { isNonInteractive = nonInteractiveRoles.includes(validRoles[0]); } return isNonInteractive; }; export { isNonInteractiveRole as default };