Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

Commit e93076c

Browse files
authored
feat(list): enter and spacebar keyboard handling for List and Listitem (#279)
test roles and keyboard handlers for list and listitem
1 parent 3759e68 commit e93076c

File tree

4 files changed

+31
-9
lines changed

4 files changed

+31
-9
lines changed

src/lib/accessibility/Behaviors/List/selectableListBehavior.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { Accessibility } from '../../types'
88
* @specification
99
* Adds role='listbox'.
1010
*/
11-
1211
const selectableListBehavior: Accessibility = (props: any) => ({
1312
attributes: {
1413
root: {

src/lib/accessibility/Behaviors/List/selectableListItemBehavior.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as keyboardKey from 'keyboard-key'
55
* @specification
66
* Adds role='option'. This role is used for a selectable item in a list.
77
* 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'.
89
*/
910

1011
const selectableListItemBehavior: Accessibility = (props: any) => ({

test/specs/components/List/ListItem-test.ts

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
})

0 commit comments

Comments
 (0)