UNPKG

@jsxtools/eslint-plugin-jsx-a11y

Version:

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

47 lines (44 loc) 1.53 kB
import { dom } from 'aria-query'; import { getProp } from '../util/module/jsx-ast-utils.js'; import { generateObjSchema } from '../util/schemas.js'; import getElementType from '../util/getElementType.js'; import getTabIndex from '../util/getTabIndex.js'; import isInteractiveElement from '../util/isInteractiveElement.js'; const errorMessage = "An element that manages focus with `aria-activedescendant` must have a tabindex"; const schema = generateObjSchema(); const ruleOfAriaActivedescendantHasTabindex = { meta: { docs: { url: "https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/aria-activedescendant-has-tabindex.md", description: "Enforce elements with aria-activedescendant are tabbable." }, schema: [schema] }, create: (context) => { const elementType = getElementType(context); return { JSXOpeningElement: (node) => { const { attributes } = node; if (getProp(attributes, "aria-activedescendant") === void 0) { return; } const type = elementType(node); if (!dom.has(type)) { return; } const tabIndex = getTabIndex(getProp(attributes, "tabIndex")); if (isInteractiveElement(type, attributes) && tabIndex === void 0) { return; } if (tabIndex >= -1) { return; } context.report({ node, message: errorMessage }); } }; } }; export { ruleOfAriaActivedescendantHasTabindex as default };