Use Banner.Title as default label for landmark region via aria-labelledby#7099
Use Banner.Title as default label for landmark region via aria-labelledby#7099
Conversation
🦋 Changeset detectedLatest commit: bffd66b The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Co-authored-by: langermank <18661030+langermank@users.noreply.github.com>
|
👋 Hi, this pull request contains changes to the source code that github/github depends on. If you are GitHub staff, we recommend testing these changes with github/github using the integration workflow. Thanks! |
|
Hi! This pull request has been marked as stale because it has been open with no activity for 60 days. You can comment on the pull request or remove the stale label to keep it open. If you do nothing, this pull request will be closed in 7 days. |
|
👋 Hi from github/github-ui! Your integration PR is ready: https://github.com/github/github-ui/pull/12621 |
There was a problem hiding this comment.
Pull request overview
This PR improves the accessibility of the Banner component by using aria-labelledby to reference the actual banner title instead of generic variant labels like "Information" or "Warning". This provides more meaningful context to screen reader users.
Changes:
- Replaced generic variant-based
aria-labelvalues witharia-labelledbythat references the Banner's title element - Added
BannerContextto share generated IDs betweenBannerandBanner.Titlecomponents - Updated tests to verify the new labeling approach and maintain backward compatibility
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/react/src/Banner/Banner.tsx | Implemented BannerContext, added useId hook for title ID generation, updated aria-labelledby/aria-label logic with proper priority order, removed obsolete labels object |
| packages/react/src/Banner/Banner.test.tsx | Updated tests to verify new aria-labelledby behavior for all variants, added tests for Banner.Title child component usage, verified custom aria-label and aria-labelledby overrides work correctly |
| .changeset/banner-aria-labelledby-title.md | Added changeset documenting this as a minor version change with appropriate description |
Banners previously labeled their landmark regions with generic variant names ("Information", "Critical", etc.) via
aria-label. This provides limited context to screen reader users. Banner regions should be labeled by their actual title content.Changes
aria-labelledbyto reference its title, whether provided viatitleprop orBanner.Titlechild componentBannerContextto share generated title IDs between Banner and Banner.TitleuseIdhook to generate unique IDs for title elementsaria-labelandaria-labelledbyprops continue to work as overridesPriority order
aria-labelledby(highest)aria-labelaria-labelledbyreferencing title (default)Example
Before:
After:
Works with both approaches:
Original prompt
Banner.Titleas the default label for the landmark region #6590💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.