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

feat(Menu): Accessibility - move MenuItem onClick handler from li to a #61

Merged
merged 7 commits into from
Aug 9, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Fixed issues ([#31](https://github.com/stardust-ui/react/issues/31)) and ([#32](https://github.com/stardust-ui/react/issues/32)) @mnajdova ([#38](https://github.com/stardust-ui/react/pull/38))
- Changing the default styles for Input component @alinais ([#25](https://github.com/stardust-ui/react/pull/25))
- Upgrade Typescript to version 3.0.1 @luzhon ([#67](https://github.com/stardust-ui/react/pull/67))
- Menu `onClick` handler moved from `li` to `a` (accessibility) ([#61](https://github.com/stardust-ui/react/pull/61))

### Features
- Behaviors for accessibility roles and other ARIA attributes @smykhailov, @jurokapsiar, @sophieH29 ([#29](https://github.com/stardust-ui/react/pull/29))
Expand Down
8 changes: 2 additions & 6 deletions src/components/Menu/MenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,13 @@ class MenuItem extends UIComponent<any, any> {
const { children, content } = this.props

return (
<ElementType
className={classes.root}
onClick={this.handleClick}
{...accessibility.attributes.root}
{...rest}
>
<ElementType className={classes.root} {...accessibility.attributes.root} {...rest}>
{childrenExist(children) ? (
children
) : (
<a
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Retested more keyboard navigation and readers.

I focus on space/enter functionality which should works on the menu item by this spec:
https://www.w3.org/TR/wai-aria-practices/examples/menubar/menubar-1/menubar-1.html#

  1. Enter/Space functionality without the readers:
  • link without the "href" attribute doesn't invoke onclick event on enter/space key
  • link with href='javascript:void(0)' invoke onclick event on enter key. Spece key doesn't invoke onclick.
  1. Enter/Space functionality with the readers:

2.1 Google/JAWS

if user navigate in virtual cursor mode then space/enter key invoke onclick event
if user navigate to menu item by tab key then works the same as without screen reader(see section above)

2.2 Edge/Narrator

space/enter key invoke onclick event in scan mode or in normal navigation

2.3 OSX/Ghrome/VoiceOver

space/enter key invoke onclick event when user press Control+Option+Space key. Just enter/Space works the same as without screen reader(see section above)

2.4 Fifefox/NVDA

if user navigate in browse mode then space/enter key invoke onclick event
if user navigate to menu item by tab key then works the same as without screen reader(see section above)

  1. Then another option is replace link with button. Then tested space/enter key works in each combination. Without reader or with readers.

Note:
in aria example supporting space was done javascript:
// Create simulated mouse event to mimic the behavior of ATs
// and let the event handler handleClick do the housekeeping.
try {
clickEvent = new MouseEvent('click', {
'view': window,
'bubbles': true,
'cancelable': true
});
}
catch (err) {
if (document.createEvent) {
// DOM Level 3 for IE 9+
clickEvent = document.createEvent('MouseEvents');
clickEvent.initEvent('click', true, true);
}
}
tgt.dispatchEvent(clickEvent);
}

className={cx('ui-menu__item__anchor', classes.anchor)}
onClick={this.handleClick}
{...accessibility.attributes.anchor}
>
{content}
Expand Down
44 changes: 29 additions & 15 deletions src/themes/teams/components/Menu/menuItemStyles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ export default {
lineHeight: 1,
position: 'relative',
verticalAlign: 'middle',
padding: `${pxToRem(14)} ${pxToRem(18)}`,
cursor: 'pointer',
display: 'block',
...(shape === 'pills' && {
...(vertical ? { margin: `0 0 ${pxToRem(5)} 0` } : { margin: `0 ${pxToRem(8)} 0 0` }),
Expand All @@ -65,12 +63,6 @@ export default {
background: variables.typePrimaryActiveBackgroundColor,
}),
}),
...(shape === 'underlined' && {
...underlinedItem(variables.defaultActiveBackgroundColor),
...(type === 'primary' && {
...underlinedItem(variables.typePrimaryActiveBorderColor),
}),
}),
},

...(active && {
Expand Down Expand Up @@ -114,8 +106,37 @@ export default {
}),
},
}),
}),
}
},

anchor: ({ props, variables }) => {
const { active, shape, type } = props

return {
color: 'inherit',
display: 'block',
...(shape === 'underlined'
? { padding: '0 0 8px 0' }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pxToRem for 8px?

: { padding: `${pxToRem(14)} ${pxToRem(18)}` }),
cursor: 'pointer',

':hover': {
color: 'inherit',
...(shape === 'underlined' && {
paddingBottom: '4px',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't it be in relative units (rem) as well?

...underlinedItem(variables.defaultActiveBackgroundColor),
...(type === 'primary' && {
...underlinedItem(variables.typePrimaryActiveBorderColor),
}),
}),
},

...(active &&
shape === 'underlined' && {
color: variables.defaultColor,
paddingBottom: '4px',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems that relative units should be used here

':hover': {},
...underlinedItem(variables.defaultActiveColor),
...(type === 'primary'
? {
Expand All @@ -126,13 +147,6 @@ export default {
fontWeight: '700',
}),
}),
}),
}
},
anchor: () => ({
color: 'inherit',
':hover': {
color: 'inherit',
},
}),
}
12 changes: 10 additions & 2 deletions test/specs/components/Menu/Menu-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ describe('Menu', () => {
const items = getItems()
const menuItems = mountWithProvider(<Menu items={items} />).find('MenuItem')

menuItems.first().simulate('click')
menuItems
.first()
.find('a')
.first()
.simulate('click')
expect(items[0].onClick).toHaveBeenCalled()
})

Expand All @@ -48,7 +52,11 @@ describe('Menu', () => {
const wrapper = mountWithProvider(<Menu items={getItems()} />)
const menuItems = wrapper.find('MenuItem')

menuItems.at(1).simulate('click')
menuItems
.at(1)
.find('a')
.first()
.simulate('click')

const updatedItems = wrapper.find('MenuItem')

Expand Down
6 changes: 5 additions & 1 deletion test/specs/components/Menu/MenuItem-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import { getTestingRenderedComponent } from 'test/utils'
import MenuItem from 'src/components/Menu/MenuItem'

describe('MenuItem', () => {
isConformant(MenuItem)
isConformant(MenuItem, {
eventTargets: {
onClick: 'a',
},
})
handlesAccessibility(MenuItem, { defaultRootRole: 'presentation' })
handlesAccessibility(MenuItem, { defaultRootRole: 'menuitem', partSelector: 'a' })

Expand Down