Irina Glushko 2389e7160b HW1 done | 3 年之前 | |
---|---|---|
.. | ||
__mocks__ | 3 年之前 | |
__tests__ | 3 年之前 | |
docs | 3 年之前 | |
lib | 3 年之前 | |
node_modules | 3 年之前 | |
scripts | 3 年之前 | |
.babelrc | 3 年之前 | |
.eslintignore | 3 年之前 | |
.eslintrc | 3 年之前 | |
CHANGELOG.md | 3 年之前 | |
FUNDING.yml | 3 年之前 | |
LICENSE.md | 3 年之前 | |
README.md | 3 年之前 | |
package.json | 3 年之前 |
Get professional support for eslint-plugin-jsx-a11y on Tidelift
Static AST checker for accessibility rules on JSX elements.
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.
If you are installing this plugin via eslint-config-airbnb
, please follow these instructions.
You'll first need to install ESLint:
# npm
npm install eslint --save-dev
# yarn
yarn add eslint --dev
Next, install eslint-plugin-jsx-a11y
:
# npm
npm install eslint-plugin-jsx-a11y --save-dev
# yarn
yarn add eslint-plugin-jsx-a11y --dev
Note: 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.
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 or strict rules at once.
Add plugin:jsx-a11y/recommended
or plugin:jsx-a11y/strict
in extends
:
{
"extends": [
"plugin:jsx-a11y/recommended"
]
}
<span>
and provide screenreader access.aria-*
props are valid.h1
, h2
, etc) elements contain accessible content.<html>
element has lang
prop.<img>
alt prop does not contain the word "image", "picture", or "photo".onClick
must be focusable.label
tag has a text label and an associated control.<audio>
and <video>
elements must have a <track>
for captions.onMouseOver
/onMouseOut
are accompanied by onFocus
/onBlur
for keyboard-only users.accessKey
prop is not used on any element to avoid complications with keyboard commands used by a screenreader.tabIndex
should only be declared on interactive elements.onBlur
over onChange
on select menus for accessibility.<div>
) that have click handlers use the role attribute.aria-*
properties supported by that role
.scope
prop is only used on <th>
elements.tabIndex
value is not greater than zero.The following rules have extra options when in recommended 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 the create-rule
script 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 out NSAccessibility (AXAPI) for an example. See Core 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 the W3 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.
chrome://accessibility/
in Chrome.accessibility off
link for any tab that you want to inspect.show accessibility tree
will appear; click this link.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 the aria-query project. We model AXObjects (that comprise the AX Tree) in the axobject-query project. The goal of the WAI-ARIA specification is to be a complete declarative interface to the AXObject model. The in-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 the MIT License.