From 73c69e6a6d8a7580c493c7903dffa12023b7abd4 Mon Sep 17 00:00:00 2001 From: Erin Doyle Date: Sat, 6 Oct 2018 12:46:43 -0400 Subject: [PATCH] Renamed rule avoid-positive-tabindex to tabindex-no-positive to be more inline with the rule naming in eslint-plugin-jsx-a11y --- .eslintrc | 4 +-- docs/rules/tabindex-no-positive.md | 32 +++++++++++++++++++ docs/rules/tabindex-uses-button.md | 4 +-- src/rules/index.js | 4 +-- ...ve-tabindex.js => tabindex-no-positive.js} | 5 ++- 5 files changed, 42 insertions(+), 7 deletions(-) create mode 100644 docs/rules/tabindex-no-positive.md rename src/rules/{avoid-positive-tabindex.js => tabindex-no-positive.js} (90%) diff --git a/.eslintrc b/.eslintrc index 1070878..9b73983 100644 --- a/.eslintrc +++ b/.eslintrc @@ -38,7 +38,7 @@ "no-use-before-define": [2, "nofunc"], "no-unused-vars": "warn", "object-shorthand": 1, - "quotes": [2, "single"], + "quotes": [2, "single", { "allowTemplateLiterals": true }], "react/forbid-prop-types": [1, { "forbid": ["any"] }], // used in conjunction with the transform-react-remove-prop-types babel plugin "react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }], "react/jsx-indent": ["error", 4], @@ -46,7 +46,7 @@ "react/jsx-uses-react": 2, "react/jsx-uses-vars": 2, "react/no-find-dom-node": "warn", // TODO: change this to error and fix findings - "react/prop-types": 0, // not currently working for stateless components: https://github.com/yannickcr/eslint-plugin-react/issues/803 + "react/prop-types": "error", "react/react-in-jsx-scope": 2, "strict": [2, "never"], "vars-on-top": "error" diff --git a/docs/rules/tabindex-no-positive.md b/docs/rules/tabindex-no-positive.md new file mode 100644 index 0000000..9049367 --- /dev/null +++ b/docs/rules/tabindex-no-positive.md @@ -0,0 +1,32 @@ +# tabindex-no-positive + +It is recommended that authors avoid positive values for the `tabindex` attribute because it is +brittle (any focusable elements added to the page without an explicit `tabindex` value greater than +zero will come last in the tab order) and can easily result in a page which is extremely difficult +to navigate, causing accessibility problems. Only use a `tabindex` of 0 for focusable elements. + + +## options + +*This rule takes no options* + +## Passes + +```jsx harmony +
+
+
+``` + +## Fails + +```jsx harmony +
+
+
+``` + +## See also + + - [This document](https://github.com/GoogleChrome/accessibility-developer-tools/wiki/Audit-Rules#ax_focus_03) + from Chrome Accessibility Developer Tools. diff --git a/docs/rules/tabindex-uses-button.md b/docs/rules/tabindex-uses-button.md index a966ed6..f681964 100644 --- a/docs/rules/tabindex-uses-button.md +++ b/docs/rules/tabindex-uses-button.md @@ -2,7 +2,7 @@ When an anchor has a `tabIndex`, but no `href` and no `role` properties, it is likely you are using it to emulate a `button`. Prefer using `role="button"` -or just use the `` element. ## options @@ -28,7 +28,7 @@ or just use the ` ``` diff --git a/src/rules/index.js b/src/rules/index.js index a3985da..50cdbd3 100644 --- a/src/rules/index.js +++ b/src/rules/index.js @@ -12,8 +12,8 @@ export default { 'redundant-alt': require('./redundant-alt').default, 'use-onblur-not-onchange': require('./use-onblur-not-onchange').default, 'valid-aria-role': require('./valid-aria-role').default, + 'tabindex-no-positive': require('./tabindex-no-positive').default, 'tabindex-uses-button': require('./tabindex-uses-button').default, - 'no-unsupported-elements-use-aria': require('./no-unsupported-elements-use-aria').default, - 'avoid-positive-tabindex': require('./avoid-positive-tabindex').default + 'no-unsupported-elements-use-aria': require('./no-unsupported-elements-use-aria').default }; diff --git a/src/rules/avoid-positive-tabindex.js b/src/rules/tabindex-no-positive.js similarity index 90% rename from src/rules/avoid-positive-tabindex.js rename to src/rules/tabindex-no-positive.js index cb643af..c5d766c 100644 --- a/src/rules/avoid-positive-tabindex.js +++ b/src/rules/tabindex-no-positive.js @@ -32,7 +32,10 @@ export const pass = [{ render: React =>
}, { when: 'the element has a negative tabIndex', - render: React =>
+ render: React =>
+}, { + when: 'the element has a tabIndex of zero', + render: React =>
}]; export const fail = [{