Skip to content

Commit b14fd80

Browse files
author
Ethan Cohen
committed
Update documentation.
1 parent 8472503 commit b14fd80

20 files changed

+142
-20
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@ Then configure the rules you want to use under the rules section.
6161

6262
## Supported Rules
6363

64-
- img-uses-alt: Enforce that img jsx elements use the alt attribute.
65-
- onClick-uses-role: Enforce that non-interactive, visible elements (such as div) that have click handlers use the role attribute.
66-
- mouseEvents-require-keyEvents: Enforce that onMouseOver/onMouseOut are accompanied by onFocus/onBlur for strictly keyboard users.
67-
- use-onblur-not-onchange: Enforce that onBlur is used instead of onChange.
68-
- no-access-key: Enforce that the accessKey prop is not used on any element to avoid complications with keyboard commands used by a screenreader.
69-
- use-label-for: Enforce that label elements have the htmlFor attribute
64+
- [img-uses-alt](docs/rules/img-uses-alt.md): Enforce that img jsx elements use the alt attribute.
65+
- [onclick-uses-role](docs/rules/onclick-uses-role): Enforce that non-interactive, visible elements (such as div) that have click handlers use the role attribute.
66+
- [mouse-events-map-to-key-events](docs/rules/mouse-events-map-to-key-events): Enforce that onMouseOver/onMouseOut are accompanied by onFocus/onBlur for strictly keyboard users.
67+
- [use-onblur-not-onchange](docs/rules/use-onblur-not-onchange): Enforce that onBlur is used instead of onChange.
68+
- [no-access-key](docs/rules/no-access-key): Enforce that the accessKey prop is not used on any element to avoid complications with keyboard commands used by a screenreader.
69+
- [use-label-for](docs/rules/use-label-for): Enforce that label elements have the htmlFor attribute
7070

7171
## License
7272

73-
MIT License.
73+
eslint-plugin-jsx-a11y is licensed under the [MIT License](LICENSE.md).

docs/rules/img-uses-alt.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# img-uses-alt
2+
3+
Enforce that an `img` element contains the `alt` prop. The alt attribute specifies an alternate text for an image, if the image cannot be displayed.
4+
5+
## Rule details
6+
7+
This rule takes no arguments. However, note that passing props as spread attribute without alt explicitly defined will cause this rule to fail. Explicitly pass down alt prop for rule to pass.
8+
9+
### Succeed
10+
```jsx
11+
<img src="foo" alt="An image of foo!" />
12+
```
13+
14+
### Fail
15+
```jsx
16+
<img src="foo" />
17+
<img {...props} />
18+
```
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# mouse-events-map-to-key-events
2+
3+
Enforce onmouseover/onmouseout are accompanied by onfocus/onblur. Coding for the keyboard is important for users with physical disabilities who cannot use a mouse, AT compatability, and screenreader users.
4+
5+
## Rule details
6+
7+
This rule takes no arguments.
8+
9+
### Succeed
10+
```jsx
11+
<div onMouseOver={ () => void 0 } onFocus={ () => void 0 } />
12+
<div onMouseOut={ () => void 0 } onBlur={ () => void 0 } />
13+
<div onMouseOver={ () => void 0 } onFocus={ () => void 0 } {...otherProps} />
14+
<div onMouseOut={ () => void 0 } onBlur={ () => void 0 } {...otherProps} />
15+
```
16+
17+
### Fail
18+
In example 3 and 4 below, even if otherProps contains onBlur and/or onFocus, this rule will still fail. Props should be passed down explicitly for rule to pass.
19+
20+
```jsx
21+
<div onMouseOver={ () => void 0 } />
22+
<div onMouseOut={ () => void 0 } />
23+
<div onMouseOver={ () => void 0 } {...otherProps} />
24+
<div onMouseOut={ () => void 0 } {...otherProps} />
25+
```

docs/rules/no-access-key.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# no-access-key
2+
3+
Enforce no accessKey prop on element. Access keys are HTML elements that allow web developers to assign keyboard shortcuts to elements. Inconsistencies between keyboard shortcuts and keyboard commands used by screenreader and keyboard only users create accessibility complications so to avoid complications, access keys should not be used.
4+
5+
## Rule details
6+
7+
This rule takes no arguments.
8+
9+
### Succeed
10+
```jsx
11+
<div />
12+
```
13+
14+
### Fail
15+
```jsx
16+
<div accessKey="h" />
17+
```

docs/rules/onclick-uses-role.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# onclick-uses-role
2+
3+
Enforce visible, non-interactive elements with click handlers use role attribute. Visible means that it is not hidden from a screen reader. Examples of non-interactive elements are `div`, `section`, and `a` elements without a href prop.The purpose of the role attribute is to identify to screenreaders the exact function of an element.
4+
5+
## Rule details
6+
7+
This rule takes no arguments.
8+
9+
### Succeed
10+
```jsx
11+
<div onClick={() => void 0} role="button" />
12+
<input type="text" onClick={() => void 0} /> // Interactive element does not require role.
13+
<a tabIndex="0" onClick={() => void 0} /> // tabIndex makes this interactive.
14+
<button onClick={() => void 0} className="foo" /> // button is interactive.
15+
<div onClick={() => void 0} role="button" aria-hidden /> // This is hidden from screenreader.
16+
```
17+
18+
### Fail
19+
```jsx
20+
<div onClick={() => void 0} />
21+
<div onClick={() => void 0} {...props} />
22+
<div onClick={() => void 0} aria-hidden={false} />
23+
<a onClick={() => void 0} />
24+
<input onClick={() => void 0} type="hidden" /> // May not be hidden from screenreader ¯\_(ツ)_/¯
25+
```

docs/rules/use-label-for.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# use-label-for
2+
3+
Enforce label tags have htmlFor attribute. Form controls using a label to identify them must have only one label that is programmatically associated with the control using: label htmlFor=[ID of control].
4+
5+
## Rule details
6+
7+
This rule takes no arguments.
8+
9+
### Succeed
10+
```jsx
11+
<input type="text" id="firstName" />
12+
<label htmlFor="firstName">First Name</label>
13+
```
14+
15+
### Fail
16+
```jsx
17+
<input type="text" id="firstName" />
18+
<label>First Name</label>
19+
```

docs/rules/use-onblur-not-onchange.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# use-onblur-not-onchange
2+
3+
Enforce usage of onBlur over onChange for accessibility. onBlur must be used instead of onChange, unless absolutely necessary and it causes no negative consequences for keyboard only or screen reader users.
4+
5+
## Rule details
6+
7+
This rule takes no arguments.
8+
9+
### Succeed
10+
```jsx
11+
<input onBlur={updateModel} />
12+
<input onBlur={handleOnBlur} onChange={handleOnChange} />
13+
```
14+
15+
### Fail
16+
```jsx
17+
<input onChange={updateModel} />
18+
```

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
},
1818
"main": "lib/index.js",
1919
"scripts": {
20-
"build": "babel src --out-dir lib",
20+
"build": "rimraf lib && babel src --out-dir lib",
2121
"prepublish": "npm run lint && npm run test && npm run build",
2222
"coveralls": "cat ./reports/coverage/lcov.info | coveralls",
2323
"lint": "eslint --config .eslintrc.js src tests",

src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
module.exports = {
44
rules: {
55
'img-uses-alt': require('./rules/img-uses-alt'),
6-
'onClick-uses-role': require('./rules/onClick-uses-role'),
7-
'mouseEvents-require-keyEvents': require('./rules/mouseEvents-require-keyEvents'),
6+
'onclick-uses-role': require('./rules/onclick-uses-role'),
7+
'mouse-events-map-to-key-events': require('./rules/mouse-events-map-to-key-events'),
88
'use-onblur-not-onchange': require('./rules/use-onblur-not-onchange'),
99
'no-access-key': require('./rules/no-access-key'),
1010
'use-label-for': require('./rules/use-label-for')

src/rules/img-uses-alt.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// Rule Definition
99
// ----------------------------------------------------------------------------
1010

11-
import hasAttribute from '../hasAttribute';
11+
import hasAttribute from '../util/hasAttribute';
1212

1313
const errorMessage = 'img elements must have an alt tag.';
1414

0 commit comments

Comments
 (0)