UNPKG

@jsxtools/eslint-plugin-jsx-a11y

Version:

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

61 lines (58 loc) 2.87 kB
const ariaQuery = require('aria-query'); const axobjectQuery = require('axobject-query'); const index = require('../index-BnNhLopb.cjs'); const index$1 = require('../index-CiY1Evc-.cjs'); const attributesComparator = require('./attributesComparator.cjs'); const roleKeys = [...ariaQuery.roles.keys()]; const elementRoleEntries = [...ariaQuery.elementRoles]; const nonInteractiveRoles = new Set(roleKeys.filter((name) => { const role = ariaQuery.roles.get(name); return !role.abstract && name !== "toolbar" && !role.superClass.some((classes) => classes.includes("widget")); }).concat( // The `progressbar` is descended from `widget`, but in practice, its // value is always `readonly`, so we treat it as a non-interactive role. "progressbar" )); const interactiveRoles = new Set(roleKeys.filter((name) => { const role = ariaQuery.roles.get(name); return !role.abstract && name !== "progressbar" && role.superClass.some((classes) => classes.includes("widget")); }).concat( // 'toolbar' does not descend from widget, but it does support // aria-activedescendant, thus in practice we treat it as a widget. "toolbar" )); const interactiveElementRoleSchemas = elementRoleEntries.flatMap( ([elementSchema, rolesArr]) => rolesArr.some((role) => interactiveRoles.has(role)) ? [elementSchema] : [] ); const nonInteractiveElementRoleSchemas = elementRoleEntries.flatMap( ([elementSchema, rolesArr]) => rolesArr.every((role) => nonInteractiveRoles.has(role)) ? [elementSchema] : [] ); const interactiveAXObjects = new Set(index.filter(index.iterFrom(axobjectQuery.AXObjects.keys()), (name) => axobjectQuery.AXObjects.get(name).type === "widget")); const interactiveElementAXObjectSchemas = [...axobjectQuery.elementAXObjects].flatMap( ([elementSchema, AXObjectsArr]) => AXObjectsArr.every((role) => interactiveAXObjects.has(role)) ? [elementSchema] : [] ); function checkIsInteractiveElement(tagName, attributes) { function elementSchemaMatcher(elementSchema) { return tagName === elementSchema.name && attributesComparator(elementSchema.attributes, attributes); } const isInherentInteractiveElement = index$1.some(index.iterFrom(interactiveElementRoleSchemas), elementSchemaMatcher); if (isInherentInteractiveElement) { return true; } const isInherentNonInteractiveElement = index$1.some(index.iterFrom(nonInteractiveElementRoleSchemas), elementSchemaMatcher); if (isInherentNonInteractiveElement) { return false; } const isInteractiveAXElement = index$1.some(index.iterFrom(interactiveElementAXObjectSchemas), elementSchemaMatcher); if (isInteractiveAXElement) { return true; } return false; } const isInteractiveElement = (tagName, attributes) => { if (!ariaQuery.dom.has(tagName)) { return false; } return checkIsInteractiveElement(tagName, attributes); }; module.exports = isInteractiveElement;