Skip to content

Commit

Permalink
feat(added aria-label to icon): added aria-label to icon
Browse files Browse the repository at this point in the history
  • Loading branch information
MichelleXBai committed May 12, 2023
1 parent 53c58e4 commit 8632f2e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/components/atoms/Button/Button.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ import { faArrowCircleRight, faArrowCircleLeft, faCoffee } from '@fortawesome/fr
</FlexCol>
<FlexCol xs={4}>
<Button>
Have some {'\u00A0'}
Have some coffee {'\u00A0'}
<FontAwesomeIcon icon={faCoffee} />
</Button>
</FlexCol>
Expand Down
4 changes: 3 additions & 1 deletion src/components/atoms/Icon/Icon.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

Use `<Icon />` whenever you want to render an icon in your application.

An `<Icon />` should be used for decorative purposes only. In the rare case where it is used to convey information, an 'ariaLabel' is required.

This library ( _and the design-system behind_ ) have a strict dependency on the **font-awesome** icon library.

This component is just a wrapper around `<FontAwesomeIcon />` from `'@fortawesome/react-fontawesome'` with just the component name and the `icon` prop renamed for convenience:
Expand Down Expand Up @@ -40,6 +42,6 @@ import { Icon, colors } from '@zopauk/react-components';
import { faCoffee } from '@fortawesome/free-solid-svg-icons';

<>
<Icon variant={faCoffee} bgColor={colors.grey} />
<Icon variant={faCoffee} bgColor={colors.grey} ariaLabel={'coffee cup'} />
</>;
```
13 changes: 11 additions & 2 deletions src/components/atoms/Icon/Icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { IconDefinition } from '@fortawesome/fontawesome-common-types';
export interface IconProps extends Omit<FontAwesomeIconProps, 'icon' | 'border'> {
variant: IconDefinition;
bgColor?: Colors[keyof Colors];
ariaLabel?: string;
}

export const RoundBadge = styled.div<{ color: Colors[keyof Colors] }>`
Expand All @@ -21,8 +22,16 @@ export const RoundBadge = styled.div<{ color: Colors[keyof Colors] }>`
padding: ${spacing[6]};
`;

export default function Icon({ variant, bgColor, className, ...rest }: IconProps) {
const renderIcon = (className?: string) => <FontAwesomeIcon {...rest} icon={variant} className={className} />;
export default function Icon({ variant, bgColor, ariaLabel, className, ...rest }: IconProps) {
const renderIcon = (className?: string) => (
<FontAwesomeIcon
{...rest}
icon={variant}
className={className}
aria-label={ariaLabel}
aria-hidden={ariaLabel ? false : true}
/>
);

return bgColor ? (
<RoundBadge className={className} color={bgColor}>
Expand Down

0 comments on commit 8632f2e

Please sign in to comment.