From 5ee8704ff5b85ec2b848dcfc10c3a8ae40a3a892 Mon Sep 17 00:00:00 2001 From: Siddharth Kshetrapal Date: Tue, 20 Aug 2024 16:05:45 +0200 Subject: [PATCH] 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 --- .changeset/cool-lobsters-nail.md | 5 ++ .../src/CircleBadge/CircleBadge.stories.tsx | 15 +++-- .../CircleOcticon/CircleOcticon.stories.tsx | 55 +++++++++---------- .../react/src/CircleOcticon/CircleOcticon.tsx | 4 +- .../react/src/Octicon/Octicon.stories.tsx | 15 +++-- 5 files changed, 52 insertions(+), 42 deletions(-) create mode 100644 .changeset/cool-lobsters-nail.md diff --git a/.changeset/cool-lobsters-nail.md b/.changeset/cool-lobsters-nail.md new file mode 100644 index 00000000000..e19428682b9 --- /dev/null +++ b/.changeset/cool-lobsters-nail.md @@ -0,0 +1,5 @@ +--- +"@primer/react": patch +--- + +Octicon: Add aria-label to the Icon instead of it's container diff --git a/packages/react/src/CircleBadge/CircleBadge.stories.tsx b/packages/react/src/CircleBadge/CircleBadge.stories.tsx index 04bfc211f8a..00e1919b132 100644 --- a/packages/react/src/CircleBadge/CircleBadge.stories.tsx +++ b/packages/react/src/CircleBadge/CircleBadge.stories.tsx @@ -3,20 +3,21 @@ import type {Meta, StoryFn} from '@storybook/react' import CircleBadge from './CircleBadge' import {ZapIcon} from '@primer/octicons-react' -export default { +const meta: Meta = { title: 'Components/CircleBadge', component: CircleBadge, -} as Meta +} +export default meta export const Default = () => ( - + ) -export const Playground: StoryFn = args => ( +export const Playground: StoryFn = ({'CircleBadge.Icon aria-label': iconAriaLabel, args}) => ( - + ) @@ -25,6 +26,7 @@ Playground.args = { size: null, inline: false, as: 'div', + 'CircleBadge.Icon aria-label': undefined, } Playground.argTypes = { @@ -44,4 +46,7 @@ Playground.argTypes = { type: 'boolean', }, }, + 'CircleBadge.Icon aria-label': { + type: 'string', + }, } diff --git a/packages/react/src/CircleOcticon/CircleOcticon.stories.tsx b/packages/react/src/CircleOcticon/CircleOcticon.stories.tsx index d2e403abaa2..4aca5c5a5eb 100644 --- a/packages/react/src/CircleOcticon/CircleOcticon.stories.tsx +++ b/packages/react/src/CircleOcticon/CircleOcticon.stories.tsx @@ -1,59 +1,54 @@ import React from 'react' import type {Meta, StoryFn} from '@storybook/react' import CircleOcticon from './CircleOcticon' +import type {CircleOcticonProps} from './CircleOcticon' import {CheckIcon} from '@primer/octicons-react' +// eslint-disable-next-line import/no-namespace +import * as Icons from '@primer/octicons-react' -export default { +const meta: Meta = { title: 'Components/CircleOcticon', component: CircleOcticon, -} as Meta +} +export default meta export const Default = () => ( - + ) -export const Playground: StoryFn = args => +type PlaygroundTypes = Omit & {icon: keyof typeof Icons} +export const Playground: StoryFn = ({icon: iconName, 'aria-label': ariaLabel, ...args}) => ( + +) Playground.args = { - icon: CheckIcon, size: 32, + icon: 'CheckIcon', + 'aria-label': undefined, sx: {backgroundColor: 'success.emphasis', color: 'fg.onEmphasis'}, } Playground.argTypes = { - icon: { - controls: false, - table: { - disable: true, - }, - }, size: { controls: { type: 'number', }, }, - sx: { - controls: false, - table: { - disable: true, - }, - }, - as: { - controls: false, - table: { - disable: true, + icon: { + control: { + type: 'select', }, + options: Object.keys(Icons), }, - ref: { - controls: false, - table: { - disable: true, - }, + 'aria-label': { + type: 'string', }, - theme: { + sx: { controls: false, - table: { - disable: true, - }, }, } diff --git a/packages/react/src/CircleOcticon/CircleOcticon.tsx b/packages/react/src/CircleOcticon/CircleOcticon.tsx index 970e69d138a..3308d82a149 100644 --- a/packages/react/src/CircleOcticon/CircleOcticon.tsx +++ b/packages/react/src/CircleOcticon/CircleOcticon.tsx @@ -10,7 +10,7 @@ export type CircleOcticonProps = { } & BoxProps function CircleOcticon(props: CircleOcticonProps) { - const {size = 32, as, icon: IconComponent, bg, ...rest} = props + const {size = 32, as, icon: IconComponent, bg, 'aria-label': ariaLabel, ...rest} = props return ( - + ) diff --git a/packages/react/src/Octicon/Octicon.stories.tsx b/packages/react/src/Octicon/Octicon.stories.tsx index 0574fbe3e48..18f9fb6a0e4 100644 --- a/packages/react/src/Octicon/Octicon.stories.tsx +++ b/packages/react/src/Octicon/Octicon.stories.tsx @@ -3,17 +3,20 @@ import type {Meta, StoryFn} from '@storybook/react' import Octicon from './Octicon' import {HeartFillIcon} from '@primer/octicons-react' -export default { +const meta: Meta = { title: 'Components/Octicon', component: Octicon, -} as Meta +} +export default meta -export const Default = () => +export const Default = () => -export const Playground: StoryFn = args => +export const Playground: StoryFn = ({'aria-label': ariaLabel, ...args}) => ( + +) Playground.args = { - ariaLabel: 'Heart', + 'aria-label': 'Heart', size: 32, } @@ -25,6 +28,8 @@ Playground.argTypes = { }, verticalAlign: { type: 'string', + control: {type: 'select'}, + options: ['middle', 'text-bottom', 'text-top', 'top', 'unset'], }, icon: { controls: false,