You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/rules/accessible-emoji.md
+5-1
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,8 @@
1
-
# [Deprecated] accessible-emoji
1
+
# jsx-a11y/accessible-emoji
2
+
3
+
❌ This rule is deprecated.
4
+
5
+
<!-- end auto-generated rule header -->
2
6
3
7
Emoji have become a common way of communicating content to the end user. To a person using a screenreader, however, they may not be aware that this content is there at all. By wrapping the emoji in a `<span>`, giving it the `role="img"`, and providing a useful description in `aria-label`, the screenreader will treat the emoji as an image in the accessibility tree with an accessible name for the end user.
Copy file name to clipboardExpand all lines: docs/rules/alt-text.md
+24-2
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,15 @@
1
-
# alt-text
1
+
# jsx-a11y/alt-text
2
+
3
+
💼 This rule is enabled in the following configs: ☑️ `recommended`, 🔒 `strict`.
4
+
5
+
<!-- end auto-generated rule header -->
2
6
3
7
Enforce that all elements that require alternative text have meaningful information to relay back to the end user. This is a critical component of accessibility for screen reader users in order for them to understand the content's purpose on the page. By default, this rule checks for alternative text on the following elements: `<img>`, `<area>`, `<input type="image">`, and `<object>`.
4
8
5
9
## How to resolve
10
+
6
11
### `<img>`
12
+
7
13
An `<img>` must have the `alt` prop set with meaningful text or as an empty string to indicate that it is an image for decoration.
8
14
9
15
For images that are being used as icons for a button or control, the `alt` prop should be set to an empty string (`alt=""`).
@@ -12,20 +18,25 @@ For images that are being used as icons for a button or control, the `alt` prop
12
18
<button>
13
19
<img src="icon.png" alt=""/>
14
20
Save
21
+
15
22
</button>
16
23
```
24
+
17
25
The content of an `alt` attribute is used to calculate the accessible label of an element, whereas the text content is used to produce a label for the element. For this reason, adding a label to an icon can produce a confusing or duplicated label on a control that already has appropriate text content.
18
26
19
27
### `<object>`
28
+
20
29
Add alternative text to all embedded `<object>` elements using either inner text, setting the `title` prop, or using the `aria-label` or `aria-labelledby` props.
21
30
22
31
### `<input type="image">`
32
+
23
33
All `<input type="image">` elements must have a non-empty `alt` prop set with a meaningful description of the image or have the `aria-label` or `aria-labelledby` props set.
24
34
25
35
### `<area>`
36
+
26
37
All clickable `<area>` elements within an image map have an `alt`, `aria-label` or `aria-labelledby` prop that describes the purpose of the link.
27
38
28
-
## Rule details
39
+
## Rule options
29
40
30
41
This rule takes one optional object argument of type object:
31
42
@@ -66,19 +77,22 @@ return (
66
77
<header>
67
78
<Image alt="Logo" src="logo.jpg"/>
68
79
</header>
80
+
69
81
);
70
82
```
71
83
72
84
Note that passing props as spread attribute without explicitly the necessary accessibility props defined will cause this rule to fail. Explicitly pass down the set of props needed for rule to pass. Use `Image` component above as a reference for destructuring and applying the prop. **It is a good thing to explicitly pass props that you expect to be passed for self-documentation.** For example:
73
85
74
86
#### Bad
87
+
75
88
```jsx
76
89
functionFoo(props) {
77
90
return<img {...props} />
78
91
}
79
92
```
80
93
81
94
#### Good
95
+
82
96
```jsx
83
97
functionFoo({ alt, ...props}) {
84
98
return<img alt={alt} {...props} />
@@ -89,6 +103,7 @@ function Foo({ alt, ...props}) {
89
103
functionFoo(props) {
90
104
const {
91
105
alt,
106
+
92
107
...otherProps
93
108
} = props;
94
109
@@ -97,6 +112,7 @@ function Foo(props) {
97
112
```
98
113
99
114
### Succeed
115
+
100
116
```jsx
101
117
<img src="foo" alt="Foo eating a sandwich."/>
102
118
<img src="foo" alt={"Foo eating a sandwich."} />
@@ -111,6 +127,7 @@ function Foo(props) {
111
127
112
128
<area aria-label="foo"/>
113
129
<area aria-labelledby="id1"/>
130
+
114
131
<area alt="This is descriptive!"/>
115
132
116
133
<input type="image" alt="This is descriptive!"/>
@@ -120,26 +137,31 @@ function Foo(props) {
120
137
```
121
138
122
139
### Fail
140
+
123
141
```jsx
124
142
<img src="foo"/>
125
143
<img {...props} />
126
144
<img {...props} alt />// Has no value
127
145
<img {...props} alt={undefined} />// Has no value
128
146
<img {...props} alt={`${undefined}`} />// Has no value
129
147
<img src="foo" role="presentation"/>// Avoid ARIA if it can be achieved without
148
+
130
149
<img src="foo" role="none"/>// Avoid ARIA if it can be achieved without
Copy file name to clipboardExpand all lines: docs/rules/anchor-ambiguous-text.md
+8-2
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,12 @@
1
-
# anchor-ambiguous-text
1
+
# jsx-a11y/anchor-ambiguous-text
2
+
3
+
☑️ This rule is _disabled_ in the `recommended` config.
4
+
5
+
<!-- end auto-generated rule header -->
2
6
3
7
Enforces `<a>` values are not exact matches for the phrases "click here", "here", "link", "a link", or "learn more". Screenreaders announce tags as links/interactive, but rely on values for context. Ambiguous anchor descriptions do not provide sufficient context for users.
4
8
5
-
## Rule details
9
+
## Rule options
6
10
7
11
This rule takes one optional object argument with the parameter `words`.
8
12
@@ -33,13 +37,15 @@ Note that this rule still disallows ambiguous `aria-label` or `alt` values.
33
37
Note that this rule is case-insensitive, trims whitespace, and ignores certain punctuation (`[,.?¿!‽¡;:]`). It only looks for **exact matches**.
34
38
35
39
### Succeed
40
+
36
41
```jsx
37
42
<a>read this tutorial</a>// passes since it is not one of the disallowed words
38
43
<a>${here}</a>// this is valid since 'here' is a variable name
39
44
<a aria-label="tutorial on using eslint-plugin-jsx-a11y">click here</a>// the aria-label supersedes the inner text
Copy file name to clipboardExpand all lines: docs/rules/anchor-has-content.md
+6-2
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,12 @@
1
-
# anchor-has-content
1
+
# jsx-a11y/anchor-has-content
2
+
3
+
💼 This rule is enabled in the following configs: ☑️ `recommended`, 🔒 `strict`.
4
+
5
+
<!-- end auto-generated rule header -->
2
6
3
7
Enforce that anchors have content and that the content is accessible to screen readers. Accessible means that it is not hidden using the `aria-hidden` prop. Refer to the references to learn about why this is important.
4
8
5
-
## Rule details
9
+
## Rule options
6
10
7
11
This rule takes one optional object argument of type object:
Copy file name to clipboardExpand all lines: docs/rules/anchor-is-valid.md
+6-2
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,8 @@
1
-
# anchor-is-valid
1
+
# jsx-a11y/anchor-is-valid
2
+
3
+
💼 This rule is enabled in the following configs: ☑️ `recommended`, 🔒 `strict`.
4
+
5
+
<!-- end auto-generated rule header -->
2
6
3
7
The HTML `<a>` element, with a valid `href` attribute, is formally defined as representing a **hyperlink**. That is, a link between one HTML document and another, or between one location inside an HTML document and another location inside the same document.
4
8
@@ -159,7 +163,7 @@ This button element can now also be used inline in text.
159
163
160
164
Once again we stress that this is an inferior implementation and some users will encounter difficulty to use your website, however, it will allow a larger group of people to interact with your website than the alternative of ignoring the rule's warning.
161
165
162
-
## Rule details
166
+
## Rule options
163
167
164
168
This rule takes one optional object argument of type object:
Copy file name to clipboardExpand all lines: docs/rules/aria-props.md
+5-1
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,8 @@
1
-
# aria-props
1
+
# jsx-a11y/aria-props
2
+
3
+
💼 This rule is enabled in the following configs: ☑️ `recommended`, 🔒 `strict`.
4
+
5
+
<!-- end auto-generated rule header -->
2
6
3
7
Elements cannot use an invalid ARIA attribute. This will fail if it finds an `aria-*` property that is not listed in [WAI-ARIA States and Properties spec](https://www.w3.org/WAI/PF/aria-1.1/states_and_properties).
Copy file name to clipboardExpand all lines: docs/rules/aria-role.md
+6-2
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,12 @@
1
-
# aria-role
1
+
# jsx-a11y/aria-role
2
+
3
+
💼 This rule is enabled in the following configs: ☑️ `recommended`, 🔒 `strict`.
4
+
5
+
<!-- end auto-generated rule header -->
2
6
3
7
Elements with ARIA roles must use a valid, non-abstract ARIA role. A reference to role definitions can be found at [WAI-ARIA](https://www.w3.org/TR/wai-aria/#role_definitions) site.
4
8
5
-
## Rule details
9
+
## Rule options
6
10
7
11
This rule takes one optional object argument of type object:
Copy file name to clipboardExpand all lines: docs/rules/aria-unsupported-elements.md
+5-1
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,8 @@
1
-
# aria-unsupported-elements
1
+
# jsx-a11y/aria-unsupported-elements
2
+
3
+
💼 This rule is enabled in the following configs: ☑️ `recommended`, 🔒 `strict`.
4
+
5
+
<!-- end auto-generated rule header -->
2
6
3
7
Certain reserved DOM elements do not support ARIA roles, states and properties. This is often because they are not visible, for example `meta`, `html`, `script`, `style`. This rule enforces that these DOM elements do not contain the `role` and/or `aria-*` props.
Copy file name to clipboardExpand all lines: docs/rules/click-events-have-key-events.md
+5-1
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,8 @@
1
-
# click-events-have-key-events
1
+
# jsx-a11y/click-events-have-key-events
2
+
3
+
💼 This rule is enabled in the following configs: ☑️ `recommended`, 🔒 `strict`.
4
+
5
+
<!-- end auto-generated rule header -->
2
6
3
7
Enforce `onClick` is accompanied by at least one of the following: `onKeyUp`, `onKeyDown`, `onKeyPress`. Coding for the keyboard is important for users with physical disabilities who cannot use a mouse, AT compatibility, and screenreader users. This does not apply for interactive or hidden elements.
Copy file name to clipboardExpand all lines: docs/rules/heading-has-content.md
+6-2
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,12 @@
1
-
# heading-has-content
1
+
# jsx-a11y/heading-has-content
2
+
3
+
💼 This rule is enabled in the following configs: ☑️ `recommended`, 🔒 `strict`.
4
+
5
+
<!-- end auto-generated rule header -->
2
6
3
7
Enforce that heading elements (`h1`, `h2`, etc.) have content and that the content is accessible to screen readers. Accessible means that it is not hidden using the `aria-hidden` prop. Refer to the references to learn about why this is important.
4
8
5
-
## Rule details
9
+
## Rule options
6
10
7
11
This rule takes one optional object argument of type object:
Copy file name to clipboardExpand all lines: docs/rules/html-has-lang.md
+5-1
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,8 @@
1
-
# html-has-lang
1
+
# jsx-a11y/html-has-lang
2
+
3
+
💼 This rule is enabled in the following configs: ☑️ `recommended`, 🔒 `strict`.
4
+
5
+
<!-- end auto-generated rule header -->
2
6
3
7
<html> elements must have the lang prop. This rule is largely superseded by the [`lang` rule](https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/HEAD/docs/rules/lang.md).
Copy file name to clipboardExpand all lines: docs/rules/img-redundant-alt.md
+6-2
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,12 @@
1
-
# img-redundant-alt
1
+
# jsx-a11y/img-redundant-alt
2
+
3
+
💼 This rule is enabled in the following configs: ☑️ `recommended`, 🔒 `strict`.
4
+
5
+
<!-- end auto-generated rule header -->
2
6
3
7
Enforce img alt attribute does not contain the word image, picture, or photo. Screenreaders already announce `img` elements as an image. There is no need to use words such as *image*, *photo*, and/or *picture*.
4
8
5
-
## Rule details
9
+
## Rule options
6
10
7
11
This rule takes one optional object argument of type object:
0 commit comments