Skip to content

Commit

Permalink
Bring inline description to be part of label (#1599)
Browse files Browse the repository at this point in the history
  • Loading branch information
siddharthkp committed Nov 15, 2021
1 parent 1b2f08d commit a2e195b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
5 changes: 5 additions & 0 deletions .changeset/action-list-description-a11y.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/components': patch
---

ActionList: Better labels and description for accessible ActionList.Item
9 changes: 2 additions & 7 deletions src/ActionList2/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,8 @@ export const Item = React.forwardRef<HTMLLIElement, ItemProps>(
aria-selected={selected}
aria-disabled={disabled ? true : undefined}
tabIndex={disabled ? undefined : -1}
aria-labelledby={labelId}
aria-describedby={[
slots.InlineDescription && inlineDescriptionId,
slots.BlockDescription && blockDescriptionId
]
.filter(Boolean)
.join(' ')}
aria-labelledby={`${labelId} ${slots.InlineDescription ? inlineDescriptionId : ''}`}
aria-describedby={slots.BlockDescription ? blockDescriptionId : undefined}
{...props}
>
<_PrivateItemWrapper>
Expand Down
29 changes: 20 additions & 9 deletions src/stories/ActionList2.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,17 @@ export function WithAvatar(): JSX.Element {
}
WithAvatar.storyName = 'With Avatar'

const projects = [
{name: 'Primer Backlog', scope: 'GitHub'},
{name: 'Accessibility', scope: 'GitHub'},
{name: 'Octicons', scope: 'github/primer'},
{name: 'Primer React', scope: 'github/primer'}
const labels = [
{name: 'blocked', color: '#86181d', description: 'Someone or something is preventing this from moving forward'},
{name: 'dependencies', color: '#0366d6', description: 'Pull requests that update a dependency file'},
{name: 'duplicate', color: '#cfd3d7', description: 'This issue or pull request already exists'},
{name: 'good first issue', color: '#7057ff', description: 'Good for newcomers'}
]

const LabelColor: React.FC<{color: string}> = ({color}) => (
<Box sx={{backgroundColor: color, width: '14px', height: '14px', borderRadius: 3}} />
)

export function WithDescription(): JSX.Element {
return (
<>
Expand All @@ -184,13 +188,13 @@ export function WithDescription(): JSX.Element {
</ActionList.Item>
))}
<ActionList.Divider />
{projects.map((project, index) => (
{labels.map((label, index) => (
<ActionList.Item key={index}>
<ActionList.LeadingVisual>
<TableIcon />
<LabelColor color={label.color} />
</ActionList.LeadingVisual>
{project.name}
<ActionList.Description variant="block">{project.scope}</ActionList.Description>
{label.name}
<ActionList.Description variant="block">{label.description}</ActionList.Description>
</ActionList.Item>
))}
</ActionList>
Expand All @@ -200,6 +204,13 @@ export function WithDescription(): JSX.Element {
}
WithDescription.storyName = 'With Description & Dividers'

const projects = [
{name: 'Primer Backlog', scope: 'GitHub'},
{name: 'Accessibility', scope: 'GitHub'},
{name: 'Octicons', scope: 'github/primer'},
{name: 'Primer React', scope: 'github/primer'}
]

export function SingleSelectListStory(): JSX.Element {
const [selectedIndex, setSelectedIndex] = React.useState(1)

Expand Down

0 comments on commit a2e195b

Please sign in to comment.