Skip to content

Commit 73c69e6

Browse files
author
Erin Doyle
committed
Renamed rule avoid-positive-tabindex to tabindex-no-positive to be more inline with the rule naming in eslint-plugin-jsx-a11y
1 parent 4bcb769 commit 73c69e6

5 files changed

Lines changed: 42 additions & 7 deletions

File tree

.eslintrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@
3838
"no-use-before-define": [2, "nofunc"],
3939
"no-unused-vars": "warn",
4040
"object-shorthand": 1,
41-
"quotes": [2, "single"],
41+
"quotes": [2, "single", { "allowTemplateLiterals": true }],
4242
"react/forbid-prop-types": [1, { "forbid": ["any"] }], // used in conjunction with the transform-react-remove-prop-types babel plugin
4343
"react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }],
4444
"react/jsx-indent": ["error", 4],
4545
"react/jsx-indent-props": ["error", 4],
4646
"react/jsx-uses-react": 2,
4747
"react/jsx-uses-vars": 2,
4848
"react/no-find-dom-node": "warn", // TODO: change this to error and fix findings
49-
"react/prop-types": 0, // not currently working for stateless components: https://github.com/yannickcr/eslint-plugin-react/issues/803
49+
"react/prop-types": "error",
5050
"react/react-in-jsx-scope": 2,
5151
"strict": [2, "never"],
5252
"vars-on-top": "error"

docs/rules/tabindex-no-positive.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# tabindex-no-positive
2+
3+
It is recommended that authors avoid positive values for the `tabindex` attribute because it is
4+
brittle (any focusable elements added to the page without an explicit `tabindex` value greater than
5+
zero will come last in the tab order) and can easily result in a page which is extremely difficult
6+
to navigate, causing accessibility problems. Only use a `tabindex` of 0 for focusable elements.
7+
8+
9+
## options
10+
11+
*This rule takes no options*
12+
13+
## Passes
14+
15+
```jsx harmony
16+
<div tabIndex={0} />
17+
<div tabIndex="0" />
18+
<div tabIndex="-1" />
19+
```
20+
21+
## Fails
22+
23+
```jsx harmony
24+
<div tabIndex={1} />
25+
<div tabIndex="1" />
26+
<div tabIndex="2" />
27+
```
28+
29+
## See also
30+
31+
- [This document](https://github.com/GoogleChrome/accessibility-developer-tools/wiki/Audit-Rules#ax_focus_03)
32+
from Chrome Accessibility Developer Tools.

docs/rules/tabindex-uses-button.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
When an anchor has a `tabIndex`, but no `href` and no `role` properties,
44
it is likely you are using it to emulate a `button`. Prefer using `role="button"`
5-
or just use the `<button` element.
5+
or just use the `<button>` element.
66

77

88
## options
@@ -28,7 +28,7 @@ or just use the `<button` element.
2828
## Fails
2929

3030
```js
31-
// fails when anchor has tabIndexbut no button
31+
// fails when anchor has tabIndex but no button
3232
<a tabindex="1"></a>
3333
```
3434

src/rules/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ export default {
1212
'redundant-alt': require('./redundant-alt').default,
1313
'use-onblur-not-onchange': require('./use-onblur-not-onchange').default,
1414
'valid-aria-role': require('./valid-aria-role').default,
15+
'tabindex-no-positive': require('./tabindex-no-positive').default,
1516
'tabindex-uses-button': require('./tabindex-uses-button').default,
16-
'no-unsupported-elements-use-aria': require('./no-unsupported-elements-use-aria').default,
17-
'avoid-positive-tabindex': require('./avoid-positive-tabindex').default
17+
'no-unsupported-elements-use-aria': require('./no-unsupported-elements-use-aria').default
1818
};
1919

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ export const pass = [{
3232
render: React => <div />
3333
}, {
3434
when: 'the element has a negative tabIndex',
35-
render: React => <div tabIndex={-2} />
35+
render: React => <div tabIndex={-1} />
36+
}, {
37+
when: 'the element has a tabIndex of zero',
38+
render: React => <div tabIndex="0" />
3639
}];
3740

3841
export const fail = [{

0 commit comments

Comments
 (0)