Skip to content

Commit 3b315c1

Browse files
a11y remediations
1 parent 1f31c3e commit 3b315c1

File tree

2 files changed

+47
-12
lines changed

2 files changed

+47
-12
lines changed

src/PageHeader/PageHeader.tsx

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,7 @@ type LinkProps = Pick<
9999
export type ParentLinkProps = React.PropsWithChildren<PageHeaderProps & LinkProps>
100100

101101
const ParentLink = React.forwardRef<HTMLAnchorElement, ParentLinkProps>(
102-
(
103-
{
104-
children,
105-
sx = {},
106-
href,
107-
'aria-label': ariaLabel = `Back to ${children}`,
108-
as = 'a',
109-
hidden = hiddenOnRegularAndWide,
110-
},
111-
ref,
112-
) => {
102+
({children, sx = {}, href, 'aria-label': ariaLabel, as = 'a', hidden = hiddenOnRegularAndWide}, ref) => {
113103
return (
114104
<>
115105
<Link
@@ -435,10 +425,33 @@ const Description: React.FC<React.PropsWithChildren<PageHeaderProps>> = ({childr
435425
)
436426
}
437427

428+
export type NavigationProps = {
429+
as?: 'nav' | 'div'
430+
'aria-label'?: React.AriaAttributes['aria-label']
431+
'aria-labelledby'?: React.AriaAttributes['aria-labelledby']
432+
} & PageHeaderProps
433+
438434
// PageHeader.Navigation: The local navigation area of the header. Visible on all viewports
439-
const Navigation: React.FC<React.PropsWithChildren<PageHeaderProps>> = ({children, sx = {}, hidden = false}) => {
435+
const Navigation: React.FC<React.PropsWithChildren<NavigationProps>> = ({
436+
children,
437+
sx = {},
438+
hidden = false,
439+
as,
440+
'aria-label': ariaLabel,
441+
'aria-labelledby': ariaLabelledBy,
442+
}) => {
443+
if (as === 'nav' && !ariaLabel && !ariaLabelledBy) {
444+
// eslint-disable-next-line no-console
445+
console.warn(
446+
'Use `aria-label` or `aria-labelledby` prop to provide an accessible label to the `nav` landmark for assistive technology',
447+
)
448+
}
440449
return (
441450
<Box
451+
as={as}
452+
// Render `aria-label` and `aria-labelledby` only on `nav` elements
453+
aria-label={as === 'nav' ? ariaLabel : undefined}
454+
aria-labelledby={as === 'nav' ? ariaLabelledBy : undefined}
442455
sx={merge<BetterSystemStyleObject>(
443456
{
444457
display: 'flex',

src/PageHeader/features.stories.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,28 @@ export const WithNavigationSlot = () => (
147147
</Box>
148148
)
149149

150+
export const WithCustomNavigation = () => (
151+
<Box sx={{padding: 3}}>
152+
<PageHeader>
153+
<PageHeader.TitleArea>
154+
<PageHeader.Title>Pull request title</PageHeader.Title>
155+
</PageHeader.TitleArea>
156+
<PageHeader.Navigation as="nav" aria-label="Item list">
157+
<ul>
158+
<li>
159+
<Link href="#" aria-current="page">
160+
Item 1
161+
</Link>
162+
</li>
163+
<li>
164+
<Link href="#">Item 2</Link>
165+
</li>
166+
</ul>
167+
</PageHeader.Navigation>
168+
</PageHeader>
169+
</Box>
170+
)
171+
150172
export const WithLeadingAndTrailingActions = () => (
151173
<Box sx={{padding: 3}}>
152174
<PageHeader>

0 commit comments

Comments
 (0)