Skip to content

Commit

Permalink
feat(icon): enhance a11y
Browse files Browse the repository at this point in the history
  • Loading branch information
sungik-choi committed Dec 18, 2024
1 parent 9a4a029 commit 9cfbee0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/bezier-react/src/components/AlphaIcon/Icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,20 @@ export const Icon = memo(
color,
source: SourceElement,
style,
'aria-hidden': ariaHidden,
'aria-label': ariaLabel,
role = 'img',
...rest
} = marginRest

Check warning on line 44 in packages/bezier-react/src/components/AlphaIcon/Icon.tsx

View check run for this annotation

Codecov / codecov/patch

packages/bezier-react/src/components/AlphaIcon/Icon.tsx#L44

Added line #L44 was not covered by tests

const isDecorative = !ariaLabel && ariaHidden !== false

return (
<SourceElement
ref={forwardedRef}
role={role}
aria-hidden={isDecorative}
aria-label={ariaLabel}
style={
{
'--b-icon-color': alphaColorTokenCssVar(color),
Expand Down
15 changes: 15 additions & 0 deletions packages/bezier-react/src/components/AlphaIcon/Icon.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,21 @@ interface IconOwnProps {
* Color from the design system's functional or semantic color.
*/
color?: FunctionalColor | SemanticColor
/**
* Accessible label for the icon
* @example "Close", "Menu", "More"
*/
'aria-label'?: string
/**
* Whether to hide the icon from screen readers
* @default true when `aria-label` is not provided
*/
'aria-hidden'?: boolean
/**
* ARIA role
* @default "img"
*/
role?: string
}

export interface IconProps
Expand Down

0 comments on commit 9cfbee0

Please sign in to comment.