Package Exports
- eslint-plugin-jsx-a11y
- eslint-plugin-jsx-a11y/lib
- eslint-plugin-jsx-a11y/lib/index.js
- eslint-plugin-jsx-a11y/lib/rules/accessible-emoji
- eslint-plugin-jsx-a11y/lib/rules/accessible-emoji.js
- eslint-plugin-jsx-a11y/lib/rules/anchor-has-content
- eslint-plugin-jsx-a11y/lib/rules/anchor-has-content.js
- eslint-plugin-jsx-a11y/lib/rules/aria-activedescendant-has-tabindex
- eslint-plugin-jsx-a11y/lib/rules/aria-props
- eslint-plugin-jsx-a11y/lib/rules/aria-props.js
- eslint-plugin-jsx-a11y/lib/rules/aria-proptypes
- eslint-plugin-jsx-a11y/lib/rules/aria-role
- eslint-plugin-jsx-a11y/lib/rules/aria-role.js
- eslint-plugin-jsx-a11y/lib/rules/aria-unsupported-elements
- eslint-plugin-jsx-a11y/lib/rules/aria-unsupported-elements.js
- eslint-plugin-jsx-a11y/lib/rules/click-events-have-key-events
- eslint-plugin-jsx-a11y/lib/rules/click-events-have-key-events.js
- eslint-plugin-jsx-a11y/lib/rules/heading-has-content
- eslint-plugin-jsx-a11y/lib/rules/heading-has-content.js
- eslint-plugin-jsx-a11y/lib/rules/html-has-lang
- eslint-plugin-jsx-a11y/lib/rules/iframe-has-title
- eslint-plugin-jsx-a11y/lib/rules/iframe-has-title.js
- eslint-plugin-jsx-a11y/lib/rules/img-redundant-alt
- eslint-plugin-jsx-a11y/lib/rules/label-has-for.js
- eslint-plugin-jsx-a11y/lib/rules/lang
- eslint-plugin-jsx-a11y/lib/rules/mouse-events-have-key-events
- eslint-plugin-jsx-a11y/lib/rules/mouse-events-have-key-events.js
- eslint-plugin-jsx-a11y/lib/rules/no-access-key
- eslint-plugin-jsx-a11y/lib/rules/no-access-key.js
- eslint-plugin-jsx-a11y/lib/rules/no-autofocus
- eslint-plugin-jsx-a11y/lib/rules/no-autofocus.js
- eslint-plugin-jsx-a11y/lib/rules/no-distracting-elements
- eslint-plugin-jsx-a11y/lib/rules/no-distracting-elements.js
- eslint-plugin-jsx-a11y/lib/rules/no-onchange
- eslint-plugin-jsx-a11y/lib/rules/no-onchange.js
- eslint-plugin-jsx-a11y/lib/rules/no-redundant-roles
- eslint-plugin-jsx-a11y/lib/rules/no-redundant-roles.js
- eslint-plugin-jsx-a11y/lib/rules/no-static-element-interactions
- eslint-plugin-jsx-a11y/lib/rules/role-has-required-aria-props
- eslint-plugin-jsx-a11y/lib/rules/role-has-required-aria-props.js
- eslint-plugin-jsx-a11y/lib/rules/role-supports-aria-props
- eslint-plugin-jsx-a11y/lib/rules/scope
- eslint-plugin-jsx-a11y/lib/rules/tabindex-no-positive
- eslint-plugin-jsx-a11y/lib/rules/tabindex-no-positive.js
- eslint-plugin-jsx-a11y/lib/util/getSuggestion
- eslint-plugin-jsx-a11y/lib/util/schemas.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (eslint-plugin-jsx-a11y) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
eslint-plugin-jsx-a11y
Static AST checker for accessibility rules on JSX elements.
Why?
Ryan Florence built out this awesome runtime-analysis tool called react-a11y. It is super useful. However, since you're probably already using linting in your project, this plugin comes for free and closer to the actual development process. Pairing this plugin with an editor lint plugin, you can bake accessibility standards into your application in real-time.
Note: This project does not replace react-a11y, but can and should be used in conjunction with it. Static analysis tools cannot determine values of variables that are being placed in props before runtime, so linting will not fail if that value is undefined and/or does not pass the lint rule.
Installation
You'll first need to install ESLint:
# npm
npm install eslint --save-dev
# yarn
yarn add eslint --devNext, install eslint-plugin-jsx-a11y:
# npm
npm install eslint-plugin-jsx-a11y --save-dev
# yarn
yarn add eslint-plugin-jsx-a11y --devNote: If you installed ESLint globally (using the -g flag in npm, or the global prefix in yarn) then you must also install eslint-plugin-jsx-a11y globally.
Usage
Add jsx-a11y to the plugins section of your .eslintrc configuration file. You can omit the eslint-plugin- prefix:
{
"plugins": [
"jsx-a11y"
]
}Then configure the rules you want to use under the rules section.
{
"rules": {
"jsx-a11y/rule-name": 2
}
}You can also enable all the recommended rules at once. Add plugin:jsx-a11y/recommended in extends:
{
"extends": {
"plugin:jsx-a11y/recommended"
}
}Supported Rules
- accessible-emoji: Enforce emojis are wrapped in and provide screenreader access.
- anchor-has-content: Enforce all anchors to contain accessible content.
- aria-activedescendant-has-tabindex: Enforce elements with aria-activedescendant are tabbable.
- aria-props: Enforce all
aria-*props are valid. - aria-proptypes: Enforce ARIA state and property values are valid.
- aria-role: Enforce that elements with ARIA roles must use a valid, non-abstract ARIA role.
- aria-unsupported-elements: Enforce that elements that do not support ARIA roles, states, and properties do not have those attributes.
- click-events-have-key-events: Enforce a clickable non-interactive element has at least one keyboard event listener.
- heading-has-content: Enforce heading (
h1,h2, etc) elements contain accessible content. - href-no-hash: Enforce an anchor element's
hrefprop value is not just#. - html-has-lang: Enforce
<html>element haslangprop. - iframe-has-title: Enforce iframe elements have a title attribute.
- img-has-alt: Enforce that
<img>JSX elements use thealtprop. - img-redundant-alt: Enforce
<img>alt prop does not contain the word "image", "picture", or "photo". - label-has-for: Enforce that
<label>elements have thehtmlForprop. - lang: Enforce lang attribute has a valid value.
- mouse-events-have-key-events: Enforce that
onMouseOver/onMouseOutare accompanied byonFocus/onBlurfor keyboard-only users. - no-access-key: Enforce that the
accessKeyprop is not used on any element to avoid complications with keyboard commands used by a screenreader. - no-autofocus: Enforce autoFocus prop is not used.
- no-distracting-elements: Enforce distracting elements are not used.
- no-onchange: Enforce usage of
onBluroveronChangeon select menus for accessibility. - no-redundant-roles: Enforce explicit role property is not the same as implicit/default role property on element.
- no-static-element-interactions: Enforce non-interactive elements have no interactive handlers.
- onclick-has-focus: Enforce that elements with
onClickhandlers must be focusable. - onclick-has-role: Enforce that non-interactive, visible elements (such as
<div>) that have click handlers use the role attribute. - role-has-required-aria-props: Enforce that elements with ARIA roles must have all required attributes for that role.
- role-supports-aria-props: Enforce that elements with explicit or implicit roles defined contain only
aria-*properties supported by thatrole. - scope: Enforce
scopeprop is only used on<th>elements. - tabindex-no-positive: Enforce
tabIndexvalue is not greater than zero.
Creating a new rule
If you are developing new rules for this project, you can use the create-rule
script to scaffold the new files.
$ ./scripts/create-rule.js my-new-ruleLicense
eslint-plugin-jsx-a11y is licensed under the MIT License.