Skip to content

Commit 0794f64

Browse files
committed
Move interactive roles and non-interactive roles lists to isInteractiveRole
1 parent fa8e6dc commit 0794f64

File tree

2 files changed

+61
-68
lines changed

2 files changed

+61
-68
lines changed

__tests__/src/util/isInteractiveRole-test.js

Lines changed: 6 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
/* eslint-env mocha */
22
import assert from 'assert';
3-
import isInteractiveRole from '../../../src/util/isInteractiveRole';
3+
import isInteractiveRole, {
4+
interactiveRoles,
5+
nonInteractiveRoles,
6+
} from '../../../src/util/isInteractiveRole';
47
import attrMock from '../../__mocks__/attrMock';
58

69
describe('isInteractiveRole', () => {
@@ -11,77 +14,14 @@ describe('isInteractiveRole', () => {
1114
});
1215
describe('elements with an interactive role', () => {
1316
it('should identify them as interactive elements', () => {
14-
[
15-
'button',
16-
'checkbox',
17-
'link',
18-
'menuitem',
19-
'menuitemcheckbox',
20-
'menuitemradio',
21-
'option',
22-
'radio',
23-
'spinbutton',
24-
'tab',
25-
'textbox',
26-
].forEach(role => expect(isInteractiveRole('div', [
17+
interactiveRoles.forEach(role => expect(isInteractiveRole('div', [
2718
attrMock('role', role)
2819
])).toBe(true));
2920
});
3021
});
3122
describe('elements with a non-interactive role', () => {
3223
it('should not identify them as interactive elements', () => {
33-
[
34-
'alert',
35-
'alertdialog',
36-
'dialog',
37-
'gridcell',
38-
'log',
39-
'marquee',
40-
'progressbar',
41-
'scrollbar',
42-
'slider',
43-
'status',
44-
'tabpanel',
45-
'timer',
46-
'tooltip',
47-
'treeitem',
48-
'combobox',
49-
'grid',
50-
'listbox',
51-
'menu',
52-
'menubar',
53-
'radiogroup',
54-
'tablist',
55-
'tree',
56-
'treegrid',
57-
'article',
58-
'columnheader',
59-
'definition',
60-
'directory',
61-
'document',
62-
'group',
63-
'heading',
64-
'img',
65-
'list',
66-
'listitem',
67-
'math',
68-
'note',
69-
'presentation',
70-
'region',
71-
'row',
72-
'rowgroup',
73-
'rowheader',
74-
'separator',
75-
'toolbar',
76-
'application',
77-
'banner',
78-
'complementary',
79-
'contentinfo',
80-
'form',
81-
'main',
82-
'navigation',
83-
'search',
84-
].forEach(role => expect(isInteractiveRole('div', [
24+
nonInteractiveRoles.forEach(role => expect(isInteractiveRole('div', [
8525
attrMock('role', role)
8626
])).toBe(false));
8727
});

src/util/isInteractiveRole.js

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { getProp, getLiteralPropValue } from 'jsx-ast-utils';
22
import DOMElements from './attributes/DOM.json';
33

44
// Map of tagNames to functions that return whether that element is interactive or not.
5-
const interactiveSet = [
5+
export const interactiveRoles = [
66
'button',
77
'checkbox',
88
'link',
@@ -16,6 +16,59 @@ const interactiveSet = [
1616
'textbox',
1717
];
1818

19+
export const nonInteractiveRoles = [
20+
'alert',
21+
'alertdialog',
22+
'dialog',
23+
'gridcell',
24+
'log',
25+
'marquee',
26+
'progressbar',
27+
'scrollbar',
28+
'slider',
29+
'status',
30+
'tabpanel',
31+
'timer',
32+
'tooltip',
33+
'treeitem',
34+
'combobox',
35+
'grid',
36+
'listbox',
37+
'menu',
38+
'menubar',
39+
'radiogroup',
40+
'tablist',
41+
'tree',
42+
'treegrid',
43+
'article',
44+
'columnheader',
45+
'definition',
46+
'directory',
47+
'document',
48+
'group',
49+
'heading',
50+
'img',
51+
'list',
52+
'listitem',
53+
'math',
54+
'note',
55+
'presentation',
56+
'region',
57+
'row',
58+
'rowgroup',
59+
'rowheader',
60+
'separator',
61+
'toolbar',
62+
'application',
63+
'banner',
64+
'complementary',
65+
'contentinfo',
66+
'form',
67+
'main',
68+
'navigation',
69+
'search',
70+
];
71+
1972
/**
2073
* Returns boolean indicating whether the given element has a role
2174
* that is associated with an interactive component. Used when an element
@@ -28,7 +81,7 @@ const isInteractiveRole = (tagName, attributes) => {
2881
if (Object.keys(DOMElements).indexOf(tagName) === -1) {
2982
return true;
3083
}
31-
return (interactiveSet.indexOf(
84+
return (interactiveRoles.indexOf(
3285
(getLiteralPropValue(getProp(attributes, 'role')) || '').toLowerCase(),
3386
) > -1);
3487
};

0 commit comments

Comments
 (0)