File tree Expand file tree Collapse file tree 2 files changed +61
-68
lines changed Expand file tree Collapse file tree 2 files changed +61
-68
lines changed Original file line number Diff line number Diff line change 1
1
/* eslint-env mocha */
2
2
import assert from 'assert' ;
3
- import isInteractiveRole from '../../../src/util/isInteractiveRole' ;
3
+ import isInteractiveRole , {
4
+ interactiveRoles ,
5
+ nonInteractiveRoles ,
6
+ } from '../../../src/util/isInteractiveRole' ;
4
7
import attrMock from '../../__mocks__/attrMock' ;
5
8
6
9
describe ( 'isInteractiveRole' , ( ) => {
@@ -11,77 +14,14 @@ describe('isInteractiveRole', () => {
11
14
} ) ;
12
15
describe ( 'elements with an interactive role' , ( ) => {
13
16
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' , [
27
18
attrMock ( 'role' , role )
28
19
] ) ) . toBe ( true ) ) ;
29
20
} ) ;
30
21
} ) ;
31
22
describe ( 'elements with a non-interactive role' , ( ) => {
32
23
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' , [
85
25
attrMock ( 'role' , role )
86
26
] ) ) . toBe ( false ) ) ;
87
27
} ) ;
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import { getProp, getLiteralPropValue } from 'jsx-ast-utils';
2
2
import DOMElements from './attributes/DOM.json' ;
3
3
4
4
// Map of tagNames to functions that return whether that element is interactive or not.
5
- const interactiveSet = [
5
+ export const interactiveRoles = [
6
6
'button' ,
7
7
'checkbox' ,
8
8
'link' ,
@@ -16,6 +16,59 @@ const interactiveSet = [
16
16
'textbox' ,
17
17
] ;
18
18
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
+
19
72
/**
20
73
* Returns boolean indicating whether the given element has a role
21
74
* that is associated with an interactive component. Used when an element
@@ -28,7 +81,7 @@ const isInteractiveRole = (tagName, attributes) => {
28
81
if ( Object . keys ( DOMElements ) . indexOf ( tagName ) === - 1 ) {
29
82
return true ;
30
83
}
31
- return ( interactiveSet . indexOf (
84
+ return ( interactiveRoles . indexOf (
32
85
( getLiteralPropValue ( getProp ( attributes , 'role' ) ) || '' ) . toLowerCase ( ) ,
33
86
) > - 1 ) ;
34
87
} ;
You can’t perform that action at this time.
0 commit comments