- Notifications
You must be signed in to change notification settings - Fork3
infofarmer/eslint-plugin-jsx-a11y
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
This is not the official eslint repo.
Get professional support for eslint-plugin-jsx-a11y on Tidelift
Static AST checker for accessibility rules on JSX elements.
Read this inother languages.
This plugin does a static evaluation of the JSX to spot accessibility issues in React apps. Because it only catches errors in static code, use it in combination with@axe-core/react to test the accessibility of the rendered DOM. Consider these tools just as one step of a larger a11y testing process and always test your apps with assistive technology.
If you are installing this plugin viaeslint-config-airbnb, please followthese instructions.
You'll first need to installESLint:
# npmnpm install eslint --save-dev# yarnyarn add eslint --dev
Next, installeslint-plugin-jsx-a11y:
# npmnpm install eslint-plugin-jsx-a11y --save-dev# yarnyarn add eslint-plugin-jsx-a11y --dev
Note: If you installed ESLint globally (using the-g flag in npm, or theglobal prefix in yarn) then you must also installeslint-plugin-jsx-a11y globally.
Addjsx-a11y to the plugins section of your.eslintrc configuration file. You can omit theeslint-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 or strict rules at once.Addplugin:jsx-a11y/recommended orplugin:jsx-a11y/strict inextends:
{"extends": ["plugin:jsx-a11y/recommended"]}As you are extending our configuration, you can omit
"plugins": ["jsx-a11y"]from your.eslintrcconfiguration file.
To enable your custom components to be checked as DOM elements, you can set global settings in yourconfiguration file by mapping each custom component name to a DOM element type.
{"settings": {"jsx-a11y": {"components": {"CityInput":"input","CustomButton":"button","MyButton":"button","RoundButton":"button" } } }}💼 Configurations enabled in.
🚫 Configurations disabled in.
☑️ Set in therecommended configuration.
🔒 Set in thestrict configuration.
❌ Deprecated.
| Name | Description | 💼 | 🚫 | ❌ |
|---|---|---|---|---|
| accessible-emoji | Enforce emojis are wrapped in<span> and provide screenreader access. | ❌ | ||
| alt-text | Enforce all elements that require alternative text have meaningful information to relay back to end user. | ☑️ 🔒 | ||
| anchor-ambiguous-text | Enforce<a> text to not exactly match "click here", "here", "link", or "a link". | ☑️ | ||
| anchor-has-content | Enforce all anchors to contain accessible content. | ☑️ 🔒 | ||
| anchor-is-valid | Enforce all anchors are valid, navigable elements. | ☑️ 🔒 | ||
| aria-activedescendant-has-tabindex | Enforce elements with aria-activedescendant are tabbable. | ☑️ 🔒 | ||
| aria-props | Enforce allaria-* 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. | ☑️ 🔒 | ||
| autocomplete-valid | Enforce that autocomplete attributes are used correctly. | ☑️ 🔒 | ||
| click-events-have-key-events | Enforce a clickable non-interactive element has at least one keyboard event listener. | ☑️ 🔒 | ||
| control-has-associated-label | Enforce that a control (an interactive element) has a text label. | ☑️ 🔒 | ||
| heading-has-content | Enforce heading (h1,h2, etc) elements contain accessible content. | ☑️ 🔒 | ||
| html-has-lang | Enforce<html> element haslang prop. | ☑️ 🔒 | ||
| iframe-has-title | Enforce iframe elements have a title attribute. | ☑️ 🔒 | ||
| img-redundant-alt | Enforce<img> alt prop does not contain the word "image", "picture", or "photo". | ☑️ 🔒 | ||
| interactive-supports-focus | Enforce that elements with interactive handlers likeonClick must be focusable. | ☑️ 🔒 | ||
| label-has-associated-control | Enforce that alabel tag has a text label and an associated control. | ☑️ 🔒 | ||
| label-has-for | Enforce that<label> elements have thehtmlFor prop. | ☑️ 🔒 | ❌ | |
| lang | Enforce lang attribute has a valid value. | |||
| media-has-caption | Enforces that<audio> and<video> elements must have a<track> for captions. | ☑️ 🔒 | ||
| mouse-events-have-key-events | Enforce thatonMouseOver/onMouseOut are accompanied byonFocus/onBlur for keyboard-only users. | ☑️ 🔒 | ||
| no-access-key | Enforce that theaccessKey prop is not used on any element to avoid complications with keyboard commands used by a screenreader. | ☑️ 🔒 | ||
| no-aria-hidden-on-focusable | Disallowaria-hidden="true" from being set on focusable elements. | |||
| no-autofocus | Enforce autoFocus prop is not used. | ☑️ 🔒 | ||
| no-distracting-elements | Enforce distracting elements are not used. | ☑️ 🔒 | ||
| no-interactive-element-to-noninteractive-role | Interactive elements should not be assigned non-interactive roles. | ☑️ 🔒 | ||
| no-noninteractive-element-interactions | Non-interactive elements should not be assigned mouse or keyboard event listeners. | ☑️ 🔒 | ||
| no-noninteractive-element-to-interactive-role | Non-interactive elements should not be assigned interactive roles. | ☑️ 🔒 | ||
| no-noninteractive-tabindex | tabIndex should only be declared on interactive elements. | ☑️ 🔒 | ||
| no-onchange | Enforce usage ofonBlur overonChange on 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 that non-interactive, visible elements (such as<div>) that have click handlers use the role attribute. | ☑️ 🔒 | ||
| prefer-tag-over-role | Enforces using semantic DOM elements over the ARIArole property. | |||
| 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 onlyaria-* properties supported by thatrole. | ☑️ 🔒 | ||
| scope | Enforcescope prop is only used on<th> elements. | ☑️ 🔒 | ||
| tabindex-no-positive | EnforcetabIndex value is not greater than zero. | ☑️ 🔒 |
The following rules have extra options when inrecommended mode:
'jsx-a11y/no-interactive-element-to-noninteractive-role':['error',{tr:['none','presentation'],},]
'jsx-a11y/no-noninteractive-element-interactions':['error',{handlers:['onClick','onMouseDown','onMouseUp','onKeyPress','onKeyDown','onKeyUp',],},]
'jsx-a11y/no-noninteractive-element-to-interactive-role':['error',{ul:['listbox','menu','menubar','radiogroup','tablist','tree','treegrid',],ol:['listbox','menu','menubar','radiogroup','tablist','tree','treegrid',],li:['menuitem','option','row','tab','treeitem'],table:['grid'],td:['gridcell'],},]
'jsx-a11y/no-noninteractive-tabindex':['error',{tags:[],roles:['tabpanel'],},]
'jsx-a11y/no-noninteractive-element-interactions':['error',{handlers:['onClick','onMouseDown','onMouseUp','onKeyPress','onKeyDown','onKeyUp',],},]
If you are developing new rules for this project, you can use thecreate-rulescript to scaffold the new files.
./scripts/create-rule.js my-new-rule
An operating system will provide an accessibility API that maps application state and content onto input/output controllers such as a screen reader, braille device, keyboard, etc.
These APIs were developed as computer interfaces shifted from buffers (which are text-based and inherently quite accessible) to graphical user interfaces (GUIs). The first attempts to make GUIs accessible involved raster image parsing to recognize characters, words, etc. This information was stored in a parallel buffer and made accessible to assistive technology (AT) devices.
As GUIs became more complex, the raster parsing approach became untenable. Accessibility APIs were developed to replace them. Check outNSAccessibility (AXAPI) for an example. SeeCore Accessibility API Mappings 1.1 for more details.
Browsers support an Accessibility API on a per operating system basis. For instance, Firefox implements the MSAA accessibility API on Windows, but does not implement the AXAPI on OSX.
From theW3 Core Accessibility API Mappings 1.1
The accessibility tree and the DOM tree are parallel structures. Roughly speaking the accessibility tree is a subset of the DOM tree. It includes the user interface objects of the user agent and the objects of the document. Accessible objects are created in the accessibility tree for every DOM element that should be exposed to assistive technology, either because it may fire an accessibility event or because it has a property, relationship or feature which needs to be exposed. Generally, if something can be trimmed out it will be, for reasons of performance and simplicity. For example, a
<span>with just a style change and no semantics may not get its own accessible object, but the style change will be exposed by other means.
Browser vendors are beginning to expose the AX Tree through inspection tools. Chrome has an experiment available to enable their inspection tool.
You can also see a text-based version of the AX Tree in Chrome in the stable release version.
- Navigate to
chrome://accessibility/in Chrome. - Toggle the
accessibility offlink for any tab that you want to inspect. - A link labeled
show accessibility treewill appear; click this link. - Balk at the wall of text that gets displayed, but then regain your conviction.
- Use the browser's find command to locate strings and values in the wall of text.
A browser constructs an AX Tree as a subset of the DOM. ARIA heavily informs the properties of this AX Tree. This AX Tree is exposed to the system level Accessibility API which mediates assistive technology agents.
We model ARIA in thearia-query project. We model AXObjects (that comprise the AX Tree) in theaxobject-query project. The goal of the WAI-ARIA specification is to be a complete declarative interface to the AXObject model. Thein-draft 1.2 version is moving towards this goal. But until then, we must consider the semantics constructs afforded by ARIA as well as those afforded by the AXObject model (AXAPI) in order to determine how HTML can be used to express user interface affordances to assistive technology users.
eslint-plugin-jsx-a11y is licensed under theMIT License.
About
Resources
Contributing
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.