Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/react/src/Banner/Banner.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ describe('Banner', () => {
render(<Banner aria-label="Test" title="test" variant="warning" />)
expect(screen.getByRole('region')).toHaveAttribute('aria-label', 'Test')
})
it('should support the `aria-labelledby` prop to override the default aria-labelledby for the landmark', () => {
render(<Banner aria-labelledby="Test" title="test" variant="warning" />)
expect(screen.getByRole('region')).toHaveAttribute('aria-labelledby', 'Test')
})

it('should default the title to a h2', () => {
render(<Banner title="test" />)
Expand Down
3 changes: 3 additions & 0 deletions packages/react/src/Banner/Banner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export type BannerProps = React.ComponentPropsWithoutRef<'section'> & {
* landmark region
*/
'aria-label'?: string
'aria-labelledby'?: string

/**
* Provide an optional className to add to the outermost element rendered by
Expand Down Expand Up @@ -85,6 +86,7 @@ const labels: Record<BannerVariant, string> = {
export const Banner = React.forwardRef<HTMLElement, BannerProps>(function Banner(
{
'aria-label': label,
'aria-labelledby': ariaLabelledby,
children,
className,
description,
Expand Down Expand Up @@ -132,6 +134,7 @@ export const Banner = React.forwardRef<HTMLElement, BannerProps>(function Banner
<section
{...rest}
aria-label={label ?? labels[variant]}
aria-labelledby={ariaLabelledby ?? title}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is the right implementation

Based on #6590, what I gather is:

  1. If the title prop (string value) is passed, use aria-label=<value-of-title-prop>
  2. If instead of title prop, Banner.Title subcomponent is used, use aria-labelledby=<id-for-the-banner-title> (Note: aria-labelledby takes an id of an element, not a string value)
  3. If either of aria-label or aria-labelledby are passed as props, ignore both 1 and 2 and use those directly.

className={clsx(className, classes.Banner)}
data-dismissible={onDismiss ? '' : undefined}
data-title-hidden={hideTitle ? '' : undefined}
Expand Down