Skip to content

Commit 43a3c43

Browse files
committed
Merge pull request #19 from evcohen/bugfix
Bugfix for onclick-uses-role failing on non-DOM components.
2 parents 1076639 + a4bf31d commit 43a3c43

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "eslint-plugin-jsx-a11y",
3-
"version": "0.6.0",
3+
"version": "0.6.1",
44
"description": "A static analysis linter of jsx and their accessibility with screen readers.",
55
"keywords": [
66
"eslint",

src/util/isInteractiveElement.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,25 @@
33
import hasAttribute from './hasAttribute';
44
import getAttributeValue from './getAttributeValue';
55

6+
const DOMElements = [
7+
"a", "abbr", "address", "area", "article",
8+
"aside", "audio", "b", "base", "bdi", "bdo", "big",
9+
"blockquote", "body", "br", "button", "canvas", "caption",
10+
"cite", "code", "col", "colgroup", "data", "datalist",
11+
"dd", "del", "details", "dfn", "dialog", "div", "dl", "dt",
12+
"em", "embed", "fieldset", "figcaption", "figure", "footer",
13+
"form", "h1", "h2", "h3", "h4", "h5", "h6", "head", "header",
14+
"hgroup", "hr", "html", "i", "iframe", "img", "input", "ins",
15+
"kbd", "keygen", "label", "legend", "li", "link", "main", "map",
16+
"mark", "menu", "menuitem", "meta", "meter", "nav", "noscript",
17+
"object", "ol", "optgroup", "option", "output", "p", "param",
18+
"picture", "pre", "progress", "q", "rp", "rt", "ruby", "s",
19+
"samp", "script", "section", "select", "small", "source", "span",
20+
"strong", "style", "sub", "summary", "sup", "table", "tbody",
21+
"td", "textarea", "tfoot", "th", "thead", "time", "title", "tr",
22+
"track", "u", "ul", "var", "video", "wbr"
23+
];
24+
625
const interactiveMap = {
726
a: attributes => {
827
const hasHref = hasAttribute(attributes, 'href');
@@ -26,6 +45,12 @@ const interactiveMap = {
2645
* it's intention is to be interacted with on the DOM.
2746
*/
2847
const isInteractiveElement = (tagName, attributes) => {
48+
// Do not test higher level JSX components, as we do not know what
49+
// low-level DOM element this maps to.
50+
if (DOMElements.indexOf(tagName) === -1) {
51+
return true;
52+
}
53+
2954
if (interactiveMap.hasOwnProperty(tagName) === false) {
3055
return false;
3156
}

tests/src/rules/onclick-uses-role.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ ruleTester.run('onclick-uses-role', rule, {
5252
{ code: '<a tabIndex="0" onClick={() => void 0} />', parserOptions },
5353
{ code: '<a role="button" onClick={() => void 0} />', parserOptions },
5454
{ code: '<a onClick={() => void 0} href="http://x.y.z" />', parserOptions },
55-
{ code: '<a onClick={() => void 0} href="http://x.y.z" tabIndex="0" />', parserOptions }
55+
{ code: '<a onClick={() => void 0} href="http://x.y.z" tabIndex="0" />', parserOptions },
56+
{ code: '<TestComponent onClick={doFoo} />', parserOptions }
5657
],
5758
invalid: [
5859
{ code: '<div onClick={() => void 0} />;', errors: [ expectedError ], parserOptions },

0 commit comments

Comments
 (0)