44
55import { dom , roles } from 'aria-query' ;
66import includes from 'array-includes' ;
7+ import fromEntries from 'object.fromentries' ;
8+
79import JSXAttributeMock from './JSXAttributeMock' ;
810import JSXElementMock from './JSXElementMock' ;
911
@@ -115,13 +117,7 @@ const nonInteractiveElementsMap: {[string]: Array<{[string]: string}>} = {
115117 ul : [ ] ,
116118} ;
117119
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 , [ ] ] ) ) ;
125121
126122Object . keys ( interactiveElementsMap )
127123 . concat ( Object . keys ( nonInteractiveElementsMap ) )
@@ -138,22 +134,25 @@ const interactiveRoles = []
138134 // aria-activedescendant, thus in practice we treat it as a widget.
139135 'toolbar' ,
140136 )
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+ ) ) ;
143141
144142const 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+ ) ) ;
150151
151152export function genElementSymbol ( openingElement : Object ) : string {
152153 return (
153154 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 ( '' ) } `
157156 : ''
158157 )
159158 ) ;
@@ -172,7 +171,7 @@ export function genInteractiveElements(): Array<JSXElementMockType> {
172171}
173172
174173export 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 (
176175 'div' ,
177176 [ JSXAttributeMock ( 'role' , value ) ] ,
178177 ) ) ;
0 commit comments