source: frontend/node_modules/eslint-plugin-jsx-a11y/README.md

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@โ€ฆ>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 23.2 KB
Lineย 
1<p align="center">
2 <a href="https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/actions">
3 <img src="https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/jsx-eslint/eslint-plugin-jsx-a11y"
4 alt="CI status" />
5 </a>
6 <a href="https://npmjs.org/package/eslint-plugin-jsx-a11y">
7 <img src="https://img.shields.io/npm/v/eslint-plugin-jsx-a11y.svg"
8 alt="npm version">
9 </a>
10 <a href="https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/HEAD/LICENSE.md">
11 <img src="https://img.shields.io/npm/l/eslint-plugin-jsx-a11y.svg"
12 alt="license">
13 </a>
14 <a href='https://coveralls.io/github/jsx-eslint/eslint-plugin-jsx-a11y?branch=master'>
15 <img src='https://coveralls.io/repos/github/jsx-eslint/eslint-plugin-jsx-a11y/badge.svg?branch=master' alt='Coverage Status' />
16 </a>
17 <a href='https://npmjs.org/package/eslint-plugin-jsx-a11y'>
18 <img src='https://img.shields.io/npm/dt/eslint-plugin-jsx-a11y.svg'
19 alt='Total npm downloads' />
20 </a>
21</p>
22
23<a href='https://tidelift.com/subscription/pkg/npm-eslint-plugin-jsx-a11y?utm_source=npm-eslint-plugin-jsx-a11y&utm_medium=referral&utm_campaign=readme'>Get professional support for eslint-plugin-jsx-a11y on Tidelift</a>
24
25# eslint-plugin-jsx-a11y
26
27Static AST checker for accessibility rules on JSX elements.
28
29#### _Read this in [other languages](https://github.com/ari-os310/eslint-plugin-jsx-a11y/blob/HEAD/translations/Translations.md)._
30
31[Mexican Spanish๐Ÿ‡ฒ๐Ÿ‡ฝ](https://github.com/ari-os310/eslint-plugin-jsx-a11y/blob/HEAD/translations/README.mx.md)
32
33## Why?
34
35This 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](https://github.com/dequelabs/axe-core-npm/tree/develop/packages/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.
36
37## Installation
38
39**If you are installing this plugin via `eslint-config-airbnb`, please follow [these instructions](https://github.com/airbnb/javascript/tree/HEAD/packages/eslint-config-airbnb#eslint-config-airbnb-1).**
40
41You'll first need to install [ESLint](https://eslint.org/docs/latest/user-guide/getting-started):
42
43```sh
44# npm
45npm install eslint --save-dev
46
47# yarn
48yarn add eslint --dev
49```
50
51Next, install `eslint-plugin-jsx-a11y`:
52
53```sh
54# npm
55npm install eslint-plugin-jsx-a11y --save-dev
56
57# yarn
58yarn add eslint-plugin-jsx-a11y --dev
59```
60
61**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.
62
63<a id="usage"></a>
64## Usage - Legacy Config (`.eslintrc`)
65
66Add `jsx-a11y` to the plugins section of your `.eslintrc` configuration file. You can omit the `eslint-plugin-` prefix:
67
68```json
69{
70 "plugins": ["jsx-a11y"]
71}
72```
73
74Then configure the rules you want to use under the rules section.
75
76```json
77{
78 "rules": {
79 "jsx-a11y/rule-name": 2
80 }
81}
82```
83
84You can also enable all the recommended or strict rules at once.
85Add `plugin:jsx-a11y/recommended` or `plugin:jsx-a11y/strict` in `extends`:
86
87```json
88{
89 "extends": ["plugin:jsx-a11y/recommended"]
90}
91```
92
93### Configurations
94
95> As you are extending our configuration, you can omit `"plugins": ["jsx-a11y"]` from your `.eslintrc` configuration file.
96
97```json
98{
99 "settings": {
100 "jsx-a11y": {
101 "polymorphicPropName": "as",
102 "components": {
103 "CityInput": "input",
104 "CustomButton": "button",
105 "MyButton": "button",
106 "RoundButton": "button"
107 },
108 "attributes": {
109 "for": ["htmlFor", "for"]
110 }
111 }
112 }
113}
114```
115
116## Usage - Flat Config (`eslint.config.js`)
117
118The default export of `eslint-plugin-jsx-a11y` is a plugin object.
119
120```js
121const jsxA11y = require('eslint-plugin-jsx-a11y');
122
123module.exports = [
124 โ€ฆ
125 {
126 files: ['**/*.{js,mjs,cjs,jsx,mjsx,ts,tsx,mtsx}'],
127 plugins: {
128 'jsx-a11y': jsxA11y,
129 },
130 languageOptions: {
131 parserOptions: {
132 ecmaFeatures: {
133 jsx: true,
134 },
135 },
136 },
137 rules: {
138 // ... any rules you want
139 'jsx-a11y/alt-text': 'error',
140 },
141 // ... others are omitted for brevity
142 },
143 โ€ฆ
144];
145```
146
147### Shareable Configs
148
149There are two shareable configs, provided by the plugin.
150
151- `flatConfigs.recommended`
152- `flatConfigs.strict`
153
154#### CJS
155
156```js
157const jsxA11y = require('eslint-plugin-jsx-a11y');
158
159export default [
160 jsxA11y.flatConfigs.recommended,
161 {
162 // Your additional configs and overrides
163 },
164];
165```
166
167#### ESM
168
169```js
170import jsxA11y from 'eslint-plugin-jsx-a11y';
171
172export default [
173 jsxA11y.flatConfigs.recommended,
174 {
175 // Your additional configs and overrides
176 },
177];
178```
179
180**Note**: Our shareable configs do NOT configure `files` or [`languageOptions.globals`](https://eslint.org/docs/latest/user-guide/configuring/configuration-files-new#configuration-objects).
181For most of the cases, you probably want to configure some of these properties yourself.
182
183```js
184const jsxA11y = require('eslint-plugin-jsx-a11y');
185const globals = require('globals');
186
187module.exports = [
188 โ€ฆ
189 {
190 files: ['**/*.{js,mjs,cjs,jsx,mjsx,ts,tsx,mtsx}'],
191 ...jsxA11y.flatConfigs.recommended,
192 languageOptions: {
193 ...jsxA11y.flatConfigs.recommended.languageOptions,
194 globals: {
195 ...globals.serviceworker,
196 ...globals.browser,
197 },
198 },
199 },
200 โ€ฆ
201];
202```
203
204#### Component Mapping
205
206To enable your custom components to be checked as DOM elements, you can set global settings in your configuration file by mapping each custom component name to a DOM element type.
207
208#### Attribute Mapping
209
210To configure the JSX property to use for attribute checking, you can set global settings in your configuration file by mapping each DOM attribute to the JSX property you want to check.
211For example, you may want to allow the `for` attribute in addition to the `htmlFor` attribute for checking label associations.
212
213#### Polymorphic Components
214
215You can optionally use the `polymorphicPropName` setting to define the prop your code uses to create polymorphic components.
216This setting will be used determine the element type in rules that require semantic context.
217
218For example, if you set the `polymorphicPropName` setting to `as` then this element:
219
220`<Box as="h3">Configurations </Box>`
221
222will be evaluated as an `h3`. If no `polymorphicPropName` is set, then the component will be evaluated as `Box`.
223
224To restrict polymorphic linting to specified components, additionally set `polymorphicAllowList` to an array of component names.
225
226โš ๏ธ Polymorphic components can make code harder to maintain; please use this feature with caution.
227
228## Supported Rules
229
230<!-- begin auto-generated rules list -->
231
232๐Ÿ’ผ Configurations enabled in.\
233๐Ÿšซ Configurations disabled in.\
234โ˜‘๏ธ Set in the `recommended` configuration.\
235๐Ÿ”’ Set in the `strict` configuration.\
236โŒ Deprecated.
237
238| Nameย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย  | Description | ๐Ÿ’ผ | ๐Ÿšซ | โŒ |
239| :----------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------- | :---- | :---- | :- |
240| [accessible-emoji](docs/rules/accessible-emoji.md) | Enforce emojis are wrapped in `<span>` and provide screen reader access. | | | โŒ |
241| [alt-text](docs/rules/alt-text.md) | Enforce all elements that require alternative text have meaningful information to relay back to end user. | โ˜‘๏ธ ๐Ÿ”’ | | |
242| [anchor-ambiguous-text](docs/rules/anchor-ambiguous-text.md) | Enforce `<a>` text to not exactly match "click here", "here", "link", or "a link". | | โ˜‘๏ธ | |
243| [anchor-has-content](docs/rules/anchor-has-content.md) | Enforce all anchors to contain accessible content. | โ˜‘๏ธ ๐Ÿ”’ | | |
244| [anchor-is-valid](docs/rules/anchor-is-valid.md) | Enforce all anchors are valid, navigable elements. | โ˜‘๏ธ ๐Ÿ”’ | | |
245| [aria-activedescendant-has-tabindex](docs/rules/aria-activedescendant-has-tabindex.md) | Enforce elements with aria-activedescendant are tabbable. | โ˜‘๏ธ ๐Ÿ”’ | | |
246| [aria-props](docs/rules/aria-props.md) | Enforce all `aria-*` props are valid. | โ˜‘๏ธ ๐Ÿ”’ | | |
247| [aria-proptypes](docs/rules/aria-proptypes.md) | Enforce ARIA state and property values are valid. | โ˜‘๏ธ ๐Ÿ”’ | | |
248| [aria-role](docs/rules/aria-role.md) | Enforce that elements with ARIA roles must use a valid, non-abstract ARIA role. | โ˜‘๏ธ ๐Ÿ”’ | | |
249| [aria-unsupported-elements](docs/rules/aria-unsupported-elements.md) | Enforce that elements that do not support ARIA roles, states, and properties do not have those attributes. | โ˜‘๏ธ ๐Ÿ”’ | | |
250| [autocomplete-valid](docs/rules/autocomplete-valid.md) | Enforce that autocomplete attributes are used correctly. | โ˜‘๏ธ ๐Ÿ”’ | | |
251| [click-events-have-key-events](docs/rules/click-events-have-key-events.md) | Enforce a clickable non-interactive element has at least one keyboard event listener. | โ˜‘๏ธ ๐Ÿ”’ | | |
252| [control-has-associated-label](docs/rules/control-has-associated-label.md) | Enforce that a control (an interactive element) has a text label. | | โ˜‘๏ธ ๐Ÿ”’ | |
253| [heading-has-content](docs/rules/heading-has-content.md) | Enforce heading (`h1`, `h2`, etc) elements contain accessible content. | โ˜‘๏ธ ๐Ÿ”’ | | |
254| [html-has-lang](docs/rules/html-has-lang.md) | Enforce `<html>` element has `lang` prop. | โ˜‘๏ธ ๐Ÿ”’ | | |
255| [iframe-has-title](docs/rules/iframe-has-title.md) | Enforce iframe elements have a title attribute. | โ˜‘๏ธ ๐Ÿ”’ | | |
256| [img-redundant-alt](docs/rules/img-redundant-alt.md) | Enforce `<img>` alt prop does not contain the word "image", "picture", or "photo". | โ˜‘๏ธ ๐Ÿ”’ | | |
257| [interactive-supports-focus](docs/rules/interactive-supports-focus.md) | Enforce that elements with interactive handlers like `onClick` must be focusable. | โ˜‘๏ธ ๐Ÿ”’ | | |
258| [label-has-associated-control](docs/rules/label-has-associated-control.md) | Enforce that a `label` tag has a text label and an associated control. | โ˜‘๏ธ ๐Ÿ”’ | | |
259| [label-has-for](docs/rules/label-has-for.md) | Enforce that `<label>` elements have the `htmlFor` prop. | | โ˜‘๏ธ ๐Ÿ”’ | โŒ |
260| [lang](docs/rules/lang.md) | Enforce lang attribute has a valid value. | | | |
261| [media-has-caption](docs/rules/media-has-caption.md) | Enforces that `<audio>` and `<video>` elements must have a `<track>` for captions. | โ˜‘๏ธ ๐Ÿ”’ | | |
262| [mouse-events-have-key-events](docs/rules/mouse-events-have-key-events.md) | Enforce that `onMouseOver`/`onMouseOut` are accompanied by `onFocus`/`onBlur` for keyboard-only users. | โ˜‘๏ธ ๐Ÿ”’ | | |
263| [no-access-key](docs/rules/no-access-key.md) | Enforce that the `accessKey` prop is not used on any element to avoid complications with keyboard commands used by a screen reader. | โ˜‘๏ธ ๐Ÿ”’ | | |
264| [no-aria-hidden-on-focusable](docs/rules/no-aria-hidden-on-focusable.md) | Disallow `aria-hidden="true"` from being set on focusable elements. | | | |
265| [no-autofocus](docs/rules/no-autofocus.md) | Enforce autoFocus prop is not used. | โ˜‘๏ธ ๐Ÿ”’ | | |
266| [no-distracting-elements](docs/rules/no-distracting-elements.md) | Enforce distracting elements are not used. | โ˜‘๏ธ ๐Ÿ”’ | | |
267| [no-interactive-element-to-noninteractive-role](docs/rules/no-interactive-element-to-noninteractive-role.md) | Interactive elements should not be assigned non-interactive roles. | โ˜‘๏ธ ๐Ÿ”’ | | |
268| [no-noninteractive-element-interactions](docs/rules/no-noninteractive-element-interactions.md) | Non-interactive elements should not be assigned mouse or keyboard event listeners. | โ˜‘๏ธ ๐Ÿ”’ | | |
269| [no-noninteractive-element-to-interactive-role](docs/rules/no-noninteractive-element-to-interactive-role.md) | Non-interactive elements should not be assigned interactive roles. | โ˜‘๏ธ ๐Ÿ”’ | | |
270| [no-noninteractive-tabindex](docs/rules/no-noninteractive-tabindex.md) | `tabIndex` should only be declared on interactive elements. | โ˜‘๏ธ ๐Ÿ”’ | | |
271| [no-onchange](docs/rules/no-onchange.md) | Enforce usage of `onBlur` over `onChange` on select menus for accessibility. | | | โŒ |
272| [no-redundant-roles](docs/rules/no-redundant-roles.md) | Enforce explicit role property is not the same as implicit/default role property on element. | โ˜‘๏ธ ๐Ÿ”’ | | |
273| [no-static-element-interactions](docs/rules/no-static-element-interactions.md) | Enforce that non-interactive, visible elements (such as `<div>`) that have click handlers use the role attribute. | โ˜‘๏ธ ๐Ÿ”’ | | |
274| [prefer-tag-over-role](docs/rules/prefer-tag-over-role.md) | Enforces using semantic DOM elements over the ARIA `role` property. | | | |
275| [role-has-required-aria-props](docs/rules/role-has-required-aria-props.md) | Enforce that elements with ARIA roles must have all required attributes for that role. | โ˜‘๏ธ ๐Ÿ”’ | | |
276| [role-supports-aria-props](docs/rules/role-supports-aria-props.md) | Enforce that elements with explicit or implicit roles defined contain only `aria-*` properties supported by that `role`. | โ˜‘๏ธ ๐Ÿ”’ | | |
277| [scope](docs/rules/scope.md) | Enforce `scope` prop is only used on `<th>` elements. | โ˜‘๏ธ ๐Ÿ”’ | | |
278| [tabindex-no-positive](docs/rules/tabindex-no-positive.md) | Enforce `tabIndex` value is not greater than zero. | โ˜‘๏ธ ๐Ÿ”’ | | |
279
280<!-- end auto-generated rules list -->
281
282The following rules have extra options when in _recommended_ mode:
283
284### no-interactive-element-to-noninteractive-role
285
286```js
287'jsx-a11y/no-interactive-element-to-noninteractive-role': [
288 'error',
289 {
290 tr: ['none', 'presentation'],
291 },
292]
293```
294
295### no-noninteractive-element-interactions
296
297```js
298'jsx-a11y/no-noninteractive-element-interactions': [
299 'error',
300 {
301 handlers: [
302 'onClick',
303 'onMouseDown',
304 'onMouseUp',
305 'onKeyPress',
306 'onKeyDown',
307 'onKeyUp',
308 ],
309 },
310]
311```
312
313### no-noninteractive-element-to-interactive-role
314
315```js
316'jsx-a11y/no-noninteractive-element-to-interactive-role': [
317 'error',
318 {
319 ul: [
320 'listbox',
321 'menu',
322 'menubar',
323 'radiogroup',
324 'tablist',
325 'tree',
326 'treegrid',
327 ],
328 ol: [
329 'listbox',
330 'menu',
331 'menubar',
332 'radiogroup',
333 'tablist',
334 'tree',
335 'treegrid',
336 ],
337 li: ['menuitem', 'option', 'row', 'tab', 'treeitem'],
338 table: ['grid'],
339 td: ['gridcell'],
340 },
341]
342```
343
344### no-noninteractive-tabindex
345
346```js
347'jsx-a11y/no-noninteractive-tabindex': [
348 'error',
349 {
350 tags: [],
351 roles: ['tabpanel'],
352 },
353]
354```
355
356### no-static-element-interactions
357
358```js
359'jsx-a11y/no-noninteractive-element-interactions': [
360 'error',
361 {
362 handlers: [
363 'onClick',
364 'onMouseDown',
365 'onMouseUp',
366 'onKeyPress',
367 'onKeyDown',
368 'onKeyUp',
369 ],
370 },
371]
372```
373
374## Creating a new rule
375
376If you are developing new rules for this project, you can use the `create-rule`
377script to scaffold the new files.
378
379```sh
380./scripts/create-rule.js my-new-rule
381```
382
383## Some background on WAI-ARIA, the AX Tree and Browsers
384
385### Accessibility API
386
387An 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.
388
389These 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.
390
391As GUIs became more complex, the raster parsing approach became untenable. Accessibility APIs were developed to replace them. Check out [NSAccessibility (AXAPI)](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Protocols/NSAccessibility_Protocol/index.html) for an example. See [Core Accessibility API Mappings 1.1](https://www.w3.org/TR/core-aam-1.1/) for more details.
392
393### Browsers
394
395Browsers 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.
396
397### The Accessibility (AX) Tree & DOM
398
399From the [W3 Core Accessibility API Mappings 1.1](https://www.w3.org/TR/core-aam-1.1/#intro_treetypes)
400
401> 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.
402
403Browser vendors are beginning to expose the AX Tree through inspection tools. Chrome has an experiment available to enable their inspection tool.
404
405You can also see a text-based version of the AX Tree in Chrome in the stable release version.
406
407#### Viewing the AX Tree in Chrome
408
4091. Navigate to `chrome://accessibility/` in Chrome.
4101. Toggle the `accessibility off` link for any tab that you want to inspect.
4111. A link labeled `show accessibility tree` will appear; click this link.
4121. Balk at the wall of text that gets displayed, but then regain your conviction.
4131. Use the browser's find command to locate strings and values in the wall of text.
414
415### Pulling it all together
416
417A 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.
418
419We model ARIA in the [aria-query](https://github.com/a11yance/aria-query) project. We model AXObjects (that comprise the AX Tree) in the [axobject-query](https://github.com/A11yance/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](https://github.com/w3c/aria/issues?q=is%3Aissue+is%3Aopen+label%3A%22ARIA+1.2%22) 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.
420
421## License
422
423eslint-plugin-jsx-a11y is licensed under the [MIT License](LICENSE.md).
Note: See TracBrowser for help on using the repository browser.