Skip to content

Commit 5ee8704

Browse files
authored
Octicon remediation: aria-label (#4811)
* correct aria-label * fix playground for Octicon and CircleOcticon * CicleOcticon: move aria-label to the icon, not the container * clean up aria-label in playground * clean up meta for CircleBadge * CircleBadge.Icon story: add aria-label in playground * Create cool-lobsters-nail.md * add aria-label to circle badge default story * add aria-label to CircleOcticon default story
1 parent 4b47151 commit 5ee8704

File tree

5 files changed

+52
-42
lines changed

5 files changed

+52
-42
lines changed

.changeset/cool-lobsters-nail.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@primer/react": patch
3+
---
4+
5+
Octicon: Add aria-label to the Icon instead of it's container

packages/react/src/CircleBadge/CircleBadge.stories.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,21 @@ import type {Meta, StoryFn} from '@storybook/react'
33
import CircleBadge from './CircleBadge'
44
import {ZapIcon} from '@primer/octicons-react'
55

6-
export default {
6+
const meta: Meta<typeof CircleBadge> = {
77
title: 'Components/CircleBadge',
88
component: CircleBadge,
9-
} as Meta<typeof CircleBadge>
9+
}
10+
export default meta
1011

1112
export const Default = () => (
1213
<CircleBadge>
13-
<CircleBadge.Icon icon={ZapIcon} />
14+
<CircleBadge.Icon icon={ZapIcon} aria-label="User badge" />
1415
</CircleBadge>
1516
)
1617

17-
export const Playground: StoryFn<typeof CircleBadge> = args => (
18+
export const Playground: StoryFn<typeof CircleBadge> = ({'CircleBadge.Icon aria-label': iconAriaLabel, args}) => (
1819
<CircleBadge {...args}>
19-
<CircleBadge.Icon icon={ZapIcon} />
20+
<CircleBadge.Icon icon={ZapIcon} aria-label={iconAriaLabel} />
2021
</CircleBadge>
2122
)
2223

@@ -25,6 +26,7 @@ Playground.args = {
2526
size: null,
2627
inline: false,
2728
as: 'div',
29+
'CircleBadge.Icon aria-label': undefined,
2830
}
2931

3032
Playground.argTypes = {
@@ -44,4 +46,7 @@ Playground.argTypes = {
4446
type: 'boolean',
4547
},
4648
},
49+
'CircleBadge.Icon aria-label': {
50+
type: 'string',
51+
},
4752
}
Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,54 @@
11
import React from 'react'
22
import type {Meta, StoryFn} from '@storybook/react'
33
import CircleOcticon from './CircleOcticon'
4+
import type {CircleOcticonProps} from './CircleOcticon'
45
import {CheckIcon} from '@primer/octicons-react'
6+
// eslint-disable-next-line import/no-namespace
7+
import * as Icons from '@primer/octicons-react'
58

6-
export default {
9+
const meta: Meta<typeof CircleOcticon> = {
710
title: 'Components/CircleOcticon',
811
component: CircleOcticon,
9-
} as Meta<typeof CircleOcticon>
12+
}
13+
export default meta
1014

1115
export const Default = () => (
12-
<CircleOcticon icon={CheckIcon} size={32} sx={{backgroundColor: 'success.emphasis', color: 'fg.onEmphasis'}} />
16+
<CircleOcticon
17+
icon={CheckIcon}
18+
size={32}
19+
sx={{backgroundColor: 'success.emphasis', color: 'fg.onEmphasis'}}
20+
aria-label="Changes approved"
21+
/>
1322
)
1423

15-
export const Playground: StoryFn<typeof CircleOcticon> = args => <CircleOcticon {...args} />
24+
type PlaygroundTypes = Omit<CircleOcticonProps, 'icon'> & {icon: keyof typeof Icons}
25+
export const Playground: StoryFn<PlaygroundTypes> = ({icon: iconName, 'aria-label': ariaLabel, ...args}) => (
26+
<CircleOcticon icon={Icons[iconName]} aria-label={ariaLabel ? ariaLabel : undefined} {...args} />
27+
)
1628

1729
Playground.args = {
18-
icon: CheckIcon,
1930
size: 32,
31+
icon: 'CheckIcon',
32+
'aria-label': undefined,
2033
sx: {backgroundColor: 'success.emphasis', color: 'fg.onEmphasis'},
2134
}
2235

2336
Playground.argTypes = {
24-
icon: {
25-
controls: false,
26-
table: {
27-
disable: true,
28-
},
29-
},
3037
size: {
3138
controls: {
3239
type: 'number',
3340
},
3441
},
35-
sx: {
36-
controls: false,
37-
table: {
38-
disable: true,
39-
},
40-
},
41-
as: {
42-
controls: false,
43-
table: {
44-
disable: true,
42+
icon: {
43+
control: {
44+
type: 'select',
4545
},
46+
options: Object.keys(Icons),
4647
},
47-
ref: {
48-
controls: false,
49-
table: {
50-
disable: true,
51-
},
48+
'aria-label': {
49+
type: 'string',
5250
},
53-
theme: {
51+
sx: {
5452
controls: false,
55-
table: {
56-
disable: true,
57-
},
5853
},
5954
}

packages/react/src/CircleOcticon/CircleOcticon.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export type CircleOcticonProps = {
1010
} & BoxProps
1111

1212
function CircleOcticon(props: CircleOcticonProps) {
13-
const {size = 32, as, icon: IconComponent, bg, ...rest} = props
13+
const {size = 32, as, icon: IconComponent, bg, 'aria-label': ariaLabel, ...rest} = props
1414
return (
1515
<Box
1616
as={as}
@@ -23,7 +23,7 @@ function CircleOcticon(props: CircleOcticonProps) {
2323
borderColor="border.default"
2424
>
2525
<Box display="flex" as={as} size={size} {...rest} alignItems="center" justifyContent="center">
26-
<IconComponent size={size} />
26+
<IconComponent size={size} aria-label={ariaLabel} />
2727
</Box>
2828
</Box>
2929
)

packages/react/src/Octicon/Octicon.stories.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,20 @@ import type {Meta, StoryFn} from '@storybook/react'
33
import Octicon from './Octicon'
44
import {HeartFillIcon} from '@primer/octicons-react'
55

6-
export default {
6+
const meta: Meta<typeof Octicon> = {
77
title: 'Components/Octicon',
88
component: Octicon,
9-
} as Meta<typeof Octicon>
9+
}
10+
export default meta
1011

11-
export const Default = () => <Octicon icon={HeartFillIcon} size={32} />
12+
export const Default = () => <Octicon icon={HeartFillIcon} aria-label="Like" size={32} />
1213

13-
export const Playground: StoryFn<typeof Octicon> = args => <Octicon icon={HeartFillIcon} {...args} />
14+
export const Playground: StoryFn<typeof Octicon> = ({'aria-label': ariaLabel, ...args}) => (
15+
<Octicon icon={HeartFillIcon} aria-label={ariaLabel ? ariaLabel : undefined} {...args} />
16+
)
1417

1518
Playground.args = {
16-
ariaLabel: 'Heart',
19+
'aria-label': 'Heart',
1720
size: 32,
1821
}
1922

@@ -25,6 +28,8 @@ Playground.argTypes = {
2528
},
2629
verticalAlign: {
2730
type: 'string',
31+
control: {type: 'select'},
32+
options: ['middle', 'text-bottom', 'text-top', 'top', 'unset'],
2833
},
2934
icon: {
3035
controls: false,

0 commit comments

Comments
 (0)