This repository was archived by the owner on Mar 4, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +31
-9
lines changed
src/lib/accessibility/Behaviors/List
test/specs/components/List Expand file tree Collapse file tree 4 files changed +31
-9
lines changed Original file line number Diff line number Diff line change @@ -8,7 +8,6 @@ import { Accessibility } from '../../types'
8
8
* @specification
9
9
* Adds role='listbox'.
10
10
*/
11
-
12
11
const selectableListBehavior : Accessibility = ( props : any ) => ( {
13
12
attributes : {
14
13
root : {
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import * as keyboardKey from 'keyboard-key'
5
5
* @specification
6
6
* Adds role='option'. This role is used for a selectable item in a list.
7
7
* Adds attribute 'aria-selected=true' based on the property 'selected'. Based on this screen readers will recognize the selected state of the item.
8
+ * Performs click action with 'Enter' and 'Spacebar' on 'root'.
8
9
*/
9
10
10
11
const selectableListItemBehavior : Accessibility = ( props : any ) => ( {
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ import * as React from 'react'
2
+ import * as keyboardKey from 'keyboard-key'
3
+ import { isConformant , handlesAccessibility } from 'test/specs/commonTests'
4
+ import { mountWithProvider } from 'test/utils'
5
+
6
+ import ListItem from 'src/components/List/ListItem'
7
+ import { selectableListItemBehavior } from 'src/lib/accessibility'
8
+
9
+ describe ( 'ListItem' , ( ) => {
10
+ isConformant ( ListItem )
11
+ handlesAccessibility ( ListItem , { defaultRootRole : 'listitem' } )
12
+
13
+ test ( 'handleClick is executed when Enter is pressed for selectable list' , ( ) => {
14
+ const onClick = jest . fn ( )
15
+ const listItem = mountWithProvider (
16
+ < ListItem accessibility = { selectableListItemBehavior } onClick = { onClick } /> ,
17
+ ) . find ( 'ListItem' )
18
+ listItem . simulate ( 'keydown' , { keyCode : keyboardKey . Enter } )
19
+ expect ( onClick ) . toHaveBeenCalledTimes ( 1 )
20
+ } )
21
+
22
+ test ( 'handleClick is executed when Spacebar is pressed for selectable list' , ( ) => {
23
+ const onClick = jest . fn ( )
24
+ const listItem = mountWithProvider (
25
+ < ListItem accessibility = { selectableListItemBehavior } onClick = { onClick } /> ,
26
+ ) . find ( 'ListItem' )
27
+ listItem . simulate ( 'keydown' , { keyCode : keyboardKey . Spacebar } )
28
+ expect ( onClick ) . toHaveBeenCalledTimes ( 1 )
29
+ } )
30
+ } )
You can’t perform that action at this time.
0 commit comments