diff --git a/src/lib/accessibility/Behaviors/List/selectableListBehavior.ts b/src/lib/accessibility/Behaviors/List/selectableListBehavior.ts index 055d0db01..77ce3215a 100644 --- a/src/lib/accessibility/Behaviors/List/selectableListBehavior.ts +++ b/src/lib/accessibility/Behaviors/List/selectableListBehavior.ts @@ -8,7 +8,6 @@ import { Accessibility } from '../../types' * @specification * Adds role='listbox'. */ - const selectableListBehavior: Accessibility = (props: any) => ({ attributes: { root: { diff --git a/src/lib/accessibility/Behaviors/List/selectableListItemBehavior.ts b/src/lib/accessibility/Behaviors/List/selectableListItemBehavior.ts index ae946d29a..271e628ba 100644 --- a/src/lib/accessibility/Behaviors/List/selectableListItemBehavior.ts +++ b/src/lib/accessibility/Behaviors/List/selectableListItemBehavior.ts @@ -5,6 +5,7 @@ import * as keyboardKey from 'keyboard-key' * @specification * Adds role='option'. This role is used for a selectable item in a list. * Adds attribute 'aria-selected=true' based on the property 'selected'. Based on this screen readers will recognize the selected state of the item. + * Performs click action with 'Enter' and 'Spacebar' on 'root'. */ const selectableListItemBehavior: Accessibility = (props: any) => ({ diff --git a/test/specs/components/List/ListItem-test.ts b/test/specs/components/List/ListItem-test.ts deleted file mode 100644 index 19e592279..000000000 --- a/test/specs/components/List/ListItem-test.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { isConformant, handlesAccessibility } from 'test/specs/commonTests' - -import ListItem from 'src/components/List/ListItem' - -describe('ListItem', () => { - isConformant(ListItem) - handlesAccessibility(ListItem, { defaultRootRole: 'listitem' }) -}) diff --git a/test/specs/components/List/ListItem-test.tsx b/test/specs/components/List/ListItem-test.tsx new file mode 100644 index 000000000..f6dd0a95f --- /dev/null +++ b/test/specs/components/List/ListItem-test.tsx @@ -0,0 +1,30 @@ +import * as React from 'react' +import * as keyboardKey from 'keyboard-key' +import { isConformant, handlesAccessibility } from 'test/specs/commonTests' +import { mountWithProvider } from 'test/utils' + +import ListItem from 'src/components/List/ListItem' +import { selectableListItemBehavior } from 'src/lib/accessibility' + +describe('ListItem', () => { + isConformant(ListItem) + handlesAccessibility(ListItem, { defaultRootRole: 'listitem' }) + + test('handleClick is executed when Enter is pressed for selectable list', () => { + const onClick = jest.fn() + const listItem = mountWithProvider( + , + ).find('ListItem') + listItem.simulate('keydown', { keyCode: keyboardKey.Enter }) + expect(onClick).toHaveBeenCalledTimes(1) + }) + + test('handleClick is executed when Spacebar is pressed for selectable list', () => { + const onClick = jest.fn() + const listItem = mountWithProvider( + , + ).find('ListItem') + listItem.simulate('keydown', { keyCode: keyboardKey.Spacebar }) + expect(onClick).toHaveBeenCalledTimes(1) + }) +})