4
4
5
5
import { dom , roles } from 'aria-query' ;
6
6
import includes from 'array-includes' ;
7
+ import fromEntries from 'object.fromentries' ;
8
+
7
9
import JSXAttributeMock from './JSXAttributeMock' ;
8
10
import JSXElementMock from './JSXElementMock' ;
9
11
@@ -115,13 +117,7 @@ const nonInteractiveElementsMap: {[string]: Array<{[string]: string}>} = {
115
117
ul : [ ] ,
116
118
} ;
117
119
118
- const indeterminantInteractiveElementsMap = domElements . reduce (
119
- ( accumulator : { [ key : string ] : Array < any > } , name : string ) : { [ key : string ] : Array < any > } => ( {
120
- ...accumulator ,
121
- [ name ] : [ ] ,
122
- } ) ,
123
- { } ,
124
- ) ;
120
+ const indeterminantInteractiveElementsMap : { [ key : string ] : Array < any > } = fromEntries ( domElements . map ( ( name : string ) => [ name , [ ] ] ) ) ;
125
121
126
122
Object . keys ( interactiveElementsMap )
127
123
. concat ( Object . keys ( nonInteractiveElementsMap ) )
@@ -138,22 +134,25 @@ const interactiveRoles = []
138
134
// aria-activedescendant, thus in practice we treat it as a widget.
139
135
'toolbar' ,
140
136
)
141
- . filter ( ( role ) => ! roles . get ( role ) . abstract )
142
- . filter ( ( role ) => roles . get ( role ) . superClass . some ( ( klasses ) => includes ( klasses , 'widget' ) ) ) ;
137
+ . filter ( ( role ) => (
138
+ ! roles . get ( role ) . abstract
139
+ && roles . get ( role ) . superClass . some ( ( klasses ) => includes ( klasses , 'widget' ) )
140
+ ) ) ;
143
141
144
142
const nonInteractiveRoles = roleNames
145
- . filter ( ( role ) => ! roles . get ( role ) . abstract )
146
- . filter ( ( role ) => ! roles . get ( role ) . superClass . some ( ( klasses ) => includes ( klasses , 'widget' ) ) )
147
- // 'toolbar' does not descend from widget, but it does support
148
- // aria-activedescendant, thus in practice we treat it as a widget.
149
- . filter ( ( role ) => ! includes ( [ 'toolbar' ] , role ) ) ;
143
+ . filter ( ( role ) => (
144
+ ! roles . get ( role ) . abstract
145
+ && ! roles . get ( role ) . superClass . some ( ( klasses ) => includes ( klasses , 'widget' ) )
146
+
147
+ // 'toolbar' does not descend from widget, but it does support
148
+ // aria-activedescendant, thus in practice we treat it as a widget.
149
+ && ! includes ( [ 'toolbar' ] , role )
150
+ ) ) ;
150
151
151
152
export function genElementSymbol ( openingElement : Object ) : string {
152
153
return (
153
154
openingElement . name . name + ( openingElement . attributes . length > 0
154
- ? `${ openingElement . attributes
155
- . map ( ( attr ) => `[${ attr . name . name } ="${ attr . value . value } "]` )
156
- . join ( '' ) } `
155
+ ? `${ openingElement . attributes . map ( ( attr ) => `[${ attr . name . name } ="${ attr . value . value } "]` ) . join ( '' ) } `
157
156
: ''
158
157
)
159
158
) ;
@@ -172,7 +171,7 @@ export function genInteractiveElements(): Array<JSXElementMockType> {
172
171
}
173
172
174
173
export function genInteractiveRoleElements(): Array< JSXElementMockType > {
175
- return [ ... interactiveRoles , 'button article' , 'fakerole button article' ] . map ( ( value ) : JSXElementMockType => JSXElementMock (
174
+ return interactiveRoles . concat ( 'button article' , 'fakerole button article' ) . map ( ( value ) : JSXElementMockType => JSXElementMock (
176
175
'div' ,
177
176
[ JSXAttributeMock ( 'role' , value ) ] ,
178
177
) ) ;
0 commit comments