Skip to content

Commit cfae57a

Browse files
author
Abdelmonaem
committed
fix banner aria-labelledby issue
1 parent b9f3f77 commit cfae57a

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

packages/react/src/Banner/Banner.test.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ describe('Banner', () => {
4949
render(<Banner aria-label="Test" title="test" variant="warning" />)
5050
expect(screen.getByRole('region')).toHaveAttribute('aria-label', 'Test')
5151
})
52+
it('should support the `aria-labelledby` prop to override the default aria-labelledby for the landmark', () => {
53+
render(<Banner aria-labelledby="Test" title="test" variant="warning" />)
54+
expect(screen.getByRole('region')).toHaveAttribute('aria-labelledby', 'Test')
55+
})
5256

5357
it('should default the title to a h2', () => {
5458
render(<Banner title="test" />)

packages/react/src/Banner/Banner.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export type BannerProps = React.ComponentPropsWithoutRef<'section'> & {
1515
* landmark region
1616
*/
1717
'aria-label'?: string
18+
'aria-labelledby'?: string
1819

1920
/**
2021
* Provide an optional className to add to the outermost element rendered by
@@ -85,6 +86,7 @@ const labels: Record<BannerVariant, string> = {
8586
export const Banner = React.forwardRef<HTMLElement, BannerProps>(function Banner(
8687
{
8788
'aria-label': label,
89+
'aria-labelledby': ariaLabelledby,
8890
children,
8991
className,
9092
description,
@@ -132,6 +134,7 @@ export const Banner = React.forwardRef<HTMLElement, BannerProps>(function Banner
132134
<section
133135
{...rest}
134136
aria-label={label ?? labels[variant]}
137+
aria-labelledby={ariaLabelledby ?? title}
135138
className={clsx(className, classes.Banner)}
136139
data-dismissible={onDismiss ? '' : undefined}
137140
data-title-hidden={hideTitle ? '' : undefined}

0 commit comments

Comments
 (0)