UNPKG

@jsxtools/eslint-plugin-jsx-a11y

Version:

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

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