Skip to content

Commit

Permalink
ActionList: a11y fixes (#1958)
Browse files Browse the repository at this point in the history
* role=none without a parent role is invalid

* Add example with Heading

* Add focus styles for high contrast mode

* Create actionlist-a11y-fixes.md
  • Loading branch information
siddharthkp authored Mar 15, 2022
1 parent 26c7784 commit be8f901
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .changeset/actionlist-a11y-fixes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@primer/react": patch
---

ActionList: Add focus styles for Windows high contrast mode
ActionList: Fix incorrect role for ActionList.Group outside ActionMenu
2 changes: 1 addition & 1 deletion src/ActionList/Group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const Group: React.FC<ActionListGroupProps> = ({
return (
<Box
as="li"
role="none"
role={listRole ? 'none' : undefined}
sx={{
'&:not(:first-child)': {marginTop: 2},
listStyle: 'none', // hide the ::marker inserted by browser's stylesheet
Expand Down
8 changes: 8 additions & 0 deletions src/ActionList/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,14 @@ export const Item = React.forwardRef<HTMLLIElement, ActionListItemProps>(
}
},

'@media (forced-colors: active)': {
':focus': {
// we set color to be transparent and let the high contrast rules
// decide what color with contrast should that be corrected to
outline: 'solid 1px transparent !important'
}
},

/** Divider styles */
'[data-component="ActionList.Item--DividerContainer"]': {
position: 'relative'
Expand Down
13 changes: 10 additions & 3 deletions src/stories/ActionList/examples.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
XIcon
} from '@primer/octicons-react'

import {ThemeProvider} from '../..'
import {Heading, ThemeProvider} from '../..'
import {ActionList} from '../../ActionList'
import BaseStyles from '../../BaseStyles'
import Avatar from '../../Avatar'
Expand Down Expand Up @@ -49,9 +49,16 @@ export function WithLinks(): JSX.Element {
<>
<h1>With Links</h1>

<p>This pattern can be seen in the repository sidebar, containing a list of links</p>
<p>This pattern can be seen in the repository sidebar, containing a list of links. </p>
<p>
The heading &quot;Details&quot; is outside the ActionList and needs to have an <code>id</code> which is passed
to ActionList with <code>aria-labelledby</code>.
</p>

<ActionList>
<Heading as="h1" id="list-heading" sx={{fontSize: 1}}>
Details
</Heading>
<ActionList aria-labelledby="list-heading">
<ActionList.LinkItem href="https://github.com/primer/react#readme">
<ActionList.LeadingVisual>
<BookIcon />
Expand Down

0 comments on commit be8f901

Please sign in to comment.