UNPKG

@jsxtools/eslint-plugin-jsx-a11y

Version:

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

29 lines (26 loc) 1.08 kB
const jsxAstUtils = require('../util/module/jsx-ast-utils.cjs'); const schemas = require('../util/schemas.cjs'); const errorMessage = "No access key attribute allowed. Inconsistencies between keyboard shortcuts and keyboard commands used by screenreaders and keyboard-only users create a11y complications."; const schema = schemas.generateObjSchema(); const ruleOfNoAccessKey = { meta: { docs: { url: "https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/no-access-key.md", description: "Enforce that the `accessKey` prop is not used on any element to avoid complications with keyboard commands used by a screenreader." }, schema: [schema] }, create: (context) => ({ JSXOpeningElement: (node) => { const accessKey = jsxAstUtils.getProp(node.attributes, "accesskey"); const accessKeyValue = jsxAstUtils.getPropValue(accessKey); if (accessKey && accessKeyValue) { context.report({ node, message: errorMessage }); } } }) }; module.exports = ruleOfNoAccessKey;