Skip to content

Commit

Permalink
fix: a11y omnibus package (#2819)
Browse files Browse the repository at this point in the history
  • Loading branch information
werdnanoslen authored Jun 20, 2024
1 parent 040e854 commit 758cd74
Show file tree
Hide file tree
Showing 25 changed files with 365 additions and 352 deletions.
4 changes: 2 additions & 2 deletions src/components/Footer/Footer/Footer.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export const MediumFooter = (): React.ReactElement => (
/>
<div className="usa-footer__contact-links mobile-lg:grid-col-6">
<SocialLinks links={socialLinkItems} />
<h3 className="usa-footer__contact-heading">Agency Contact Center</h3>
<p className="usa-footer__contact-heading">Agency Contact Center</p>
<Address
size="medium"
items={[
Expand Down Expand Up @@ -225,7 +225,7 @@ export const BigFooter = (): React.ReactElement => (
/>
<div className="usa-footer__contact-links mobile-lg:grid-col-6">
<SocialLinks links={socialLinkItems} />
<h3 className="usa-footer__contact-heading">Agency Contact Center</h3>
<p className="usa-footer__contact-heading">Agency Contact Center</p>
<Address
size="big"
items={[
Expand Down
3 changes: 1 addition & 2 deletions src/components/Footer/SocialLinks/SocialLinks.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable jsx-a11y/anchor-is-valid */
import React from 'react'
import { render, screen } from '@testing-library/react'
import { render } from '@testing-library/react'

import { SocialLinks, SocialLink } from './SocialLinks'

Expand Down Expand Up @@ -43,6 +43,5 @@ describe('SocialLink component', () => {
const link = container.querySelector('.usa-social-link')
expect(link).toBeInTheDocument()
expect(link).toHaveAttribute('title', 'Instagram')
expect(screen.getByRole('img')).toHaveAttribute('name', 'Instagram')
})
})
6 changes: 5 additions & 1 deletion src/components/Footer/SocialLinks/SocialLinks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ export const SocialLink = ({
return (
<a className="usa-social-link" {...props} title={name}>
{IconComponent && (
<IconComponent className="usa-social-link__icon" name={name} />
<IconComponent
className="usa-social-link__icon"
name={name}
aria-hidden="true"
/>
)}
</a>
)
Expand Down
14 changes: 12 additions & 2 deletions src/components/Icon/Icon.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,23 @@ Source: https://designsystem.digital.gov/components/icon/
argTypes: {
size: {
control: {
type: 'select',
options: [3, 4, 5, 6, 7, 8, 9],
type: 'number',
min: 3,
max: 9,
step: 1,
},
},
'aria-label': {
name: 'aria-label',
description: 'Add this if and only aria-hidden is false',
control: {
type: 'text',
},
},
},
args: {
size: 4,
'aria-hidden': true,
},
}

Expand Down
10 changes: 10 additions & 0 deletions src/components/Icon/Icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ export const makeUSWDSIcon = (
...iconProps,
}

if (
'img' === role &&
!iconProps['aria-hidden'] &&
!iconProps['aria-label'] &&
!iconProps['aria-labelledby']
) {
console.warn(
`Icon with img role is missing an accessible label. https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/Img_role#associated_wai-aria_roles_states_and_properties`
)
}
return <Component {...finalProps} />
}
IconFunctionalComponent.displayName = Component.displayName
Expand Down
7 changes: 5 additions & 2 deletions src/components/Icon/Icons.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@ Source: https://designsystem.digital.gov/components/icon/
argTypes: {
size: {
control: {
type: 'select',
options: [3, 4, 5, 6, 7, 8, 9],
type: 'number',
min: 3,
max: 9,
step: 1,
},
},
},
args: {
size: 4,
'aria-hidden': true,
},
}

Expand Down
32 changes: 16 additions & 16 deletions src/components/IconList/IconList.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@ export const Default = (): ReactElement => (
<IconList>
<IconListItem>
<IconListIcon className="text-green">
<Icon.CheckCircle />
<Icon.CheckCircle aria-hidden="true" />
</IconListIcon>
<IconListContent>
Wash your hands for 20 seconds with soap
</IconListContent>
</IconListItem>
<IconListItem>
<IconListIcon className="text-green">
<Icon.CheckCircle />
<Icon.CheckCircle aria-hidden="true" />
</IconListIcon>
<IconListContent>Stay six feet away from others</IconListContent>
</IconListItem>
<IconListItem>
<IconListIcon className="text-red">
<Icon.Cancel />
<Icon.Cancel aria-hidden="true" />
</IconListIcon>
<IconListContent>Avoid large gatherings</IconListContent>
</IconListItem>
Expand All @@ -51,27 +51,27 @@ export const SimpleContent = (): ReactElement => (
<IconList className="usa-icon-list--primary">
<IconListItem>
<IconListIcon>
<Icon.ThumbUpAlt />
<Icon.ThumbUpAlt aria-hidden="true" />
</IconListIcon>
<IconListContent>No processing lines</IconListContent>
</IconListItem>
<IconListItem>
<IconListIcon>
<Icon.ThumbUpAlt />
<Icon.ThumbUpAlt aria-hidden="true" />
</IconListIcon>
<IconListContent>
Access to expedited entry benefits in other countries
</IconListContent>
</IconListItem>
<IconListItem>
<IconListIcon>
<Icon.ThumbUpAlt />
<Icon.ThumbUpAlt aria-hidden="true" />
</IconListIcon>
<IconListContent>Available at major U.S. airports</IconListContent>
</IconListItem>
<IconListItem>
<IconListIcon>
<Icon.ThumbUpAlt />
<Icon.ThumbUpAlt aria-hidden="true" />
</IconListIcon>
<IconListContent>Reduced wait times</IconListContent>
</IconListItem>
Expand All @@ -83,7 +83,7 @@ export const RichContent = (): ReactElement => (
<IconList>
<IconListItem>
<IconListIcon className="text-ink">
<Icon.CheckCircle />
<Icon.CheckCircle aria-hidden="true" />
</IconListIcon>
<IconListContent>
<IconListTitle type="h3">Donate cash when possible.</IconListTitle>
Expand All @@ -98,7 +98,7 @@ export const RichContent = (): ReactElement => (
</IconListItem>
<IconListItem>
<IconListIcon className="text-ink">
<Icon.CheckCircle />
<Icon.CheckCircle aria-hidden="true" />
</IconListIcon>
<IconListContent>
<IconListTitle type="h3">
Expand All @@ -113,7 +113,7 @@ export const RichContent = (): ReactElement => (
</IconListItem>
<IconListItem>
<IconListIcon className="text-ink">
<Icon.CheckCircle />
<Icon.CheckCircle aria-hidden="true" />
</IconListIcon>
<IconListContent>
<IconListTitle type="h3">
Expand All @@ -140,7 +140,7 @@ export const CustomSizeWithRichContent = (): ReactElement => (
<IconList className="usa-icon-list--size-lg">
<IconListItem>
<IconListIcon className="text-green">
<Icon.AttachMoney />
<Icon.AttachMoney aria-hidden="true" />
</IconListIcon>
<IconListContent>
<IconListTitle type="h3">Let the sun shine.</IconListTitle>
Expand All @@ -154,7 +154,7 @@ export const CustomSizeWithRichContent = (): ReactElement => (
</IconListItem>
<IconListItem>
<IconListIcon className="text-green">
<Icon.AttachMoney />
<Icon.AttachMoney aria-hidden="true" />
</IconListIcon>
<IconListContent>
<IconListTitle type="h3">Adjust your schedule.</IconListTitle>
Expand All @@ -168,7 +168,7 @@ export const CustomSizeWithRichContent = (): ReactElement => (
</IconListItem>
<IconListItem>
<IconListIcon className="text-green">
<Icon.AttachMoney />
<Icon.AttachMoney aria-hidden="true" />
</IconListIcon>
<IconListContent>
<IconListTitle type="h3">Fill it up.</IconListTitle>
Expand All @@ -188,7 +188,7 @@ export const CustomSize = (): ReactElement => (
<IconList className="usa-icon-list--size-lg">
<IconListItem>
<IconListIcon className="text-blue">
<Icon.Help />
<Icon.Help aria-hidden="true" />
</IconListIcon>
<IconListContent>
<span className="text-bold">Timing.</span> Is now the right time to
Expand All @@ -197,7 +197,7 @@ export const CustomSize = (): ReactElement => (
</IconListItem>
<IconListItem>
<IconListIcon className="text-blue">
<Icon.Help />
<Icon.Help aria-hidden="true" />
</IconListIcon>
<IconListContent>
<span className="text-bold">Funding.</span> Do I have enough money to
Expand All @@ -206,7 +206,7 @@ export const CustomSize = (): ReactElement => (
</IconListItem>
<IconListItem>
<IconListIcon className="text-blue">
<Icon.Help />
<Icon.Help aria-hidden="true" />
</IconListIcon>
<IconListContent>
<span className="text-bold">Need.</span> Will this business fill a real
Expand Down
4 changes: 3 additions & 1 deletion src/components/LanguageSelector/LanguageSelectorButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ type LanguageSelectorButtonProps = {
labelAttr?: string
isOpen?: boolean
onToggle: () => void
controls?: string
}

export const LanguageSelectorButton = ({
Expand All @@ -14,6 +15,7 @@ export const LanguageSelectorButton = ({
isOpen,
onToggle,
className,
controls,
...buttonProps
}: LanguageSelectorButtonProps &
JSX.IntrinsicElements['button']): React.ReactElement => {
Expand All @@ -28,7 +30,7 @@ export const LanguageSelectorButton = ({
data-testid="languageSelectorButton"
className={classes}
aria-expanded={isOpen}
aria-controls="language-options"
aria-controls={controls}
onClick={(): void => onToggle()}
type="button"
{...buttonProps}>
Expand Down
4 changes: 3 additions & 1 deletion src/components/LanguageSelector/LanguageSelectorDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const LanguageSelectorDropdown: React.FC<LanguageSelectorProps> = ({
className
)
const displayLabel = langs.find((langDef) => langDef.attr === displayLang)
const menuID = 'language-options'

return (
<div className={classes} data-testid="languageSelector" {...divProps}>
Expand All @@ -63,12 +64,13 @@ const LanguageSelectorDropdown: React.FC<LanguageSelectorProps> = ({
className={classes}
label={displayLabel?.label || label || langs[0].label}
isOpen={isOpen}
controls={menuID}
onToggle={() => setIsOpen((prevIsOpen) => !prevIsOpen)}
/>
<Menu
items={generateMenuItems(langs)}
isOpen={isOpen}
id="language-options"
id={menuID}
type="language"
/>
</li>
Expand Down
Loading

0 comments on commit 758cd74

Please sign in to comment.