feat(a11y): allow custom aria label on side navigation [AC-4119]#1340
feat(a11y): allow custom aria label on side navigation [AC-4119]#1340Stefan3002 merged 1 commit intocanonical:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Adds support for customizing the accessible name of the SideNavigation landmark by allowing a consumer-provided aria label to be applied directly to the inner <nav> element, helping avoid unique-landmark accessibility violations when multiple navigation landmarks exist on a page.
Changes:
- Introduced a new
ariaLabelprop onSideNavigation. - Applied the provided label as
aria-labelon the internal<nav>element.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| */ | ||
| ariaLabel?: string; | ||
| }, | ||
| HTMLProps<HTMLDivElement> |
There was a problem hiding this comment.
There are now two different ways a consumer can set a label: passing the standard aria-label attribute (via ...props) will apply it to the outer <div>, while the new ariaLabel prop applies to the inner <nav>. This is easy to get wrong and can still leave the navigation landmark unnamed. Consider supporting the standard aria-label API by extracting props["aria-label"] and applying it to <nav> (and omitting it from the <div> props), or alternatively introduce a navProps object to pass attributes directly to the <nav> element.
| HTMLProps<HTMLDivElement> | |
| Omit<HTMLProps<HTMLDivElement>, "aria-label"> |
| {...props} | ||
| > | ||
| <nav className={navClassName}> | ||
| <nav aria-label={ariaLabel} className={navClassName}> | ||
| {children ?? generateItems(items, listClassName, linkComponent, dark)} | ||
| </nav> |
There was a problem hiding this comment.
New behavior (ariaLabel controlling the <nav> landmark name) isn’t covered by tests. Since this component already has unit tests (src/components/SideNavigation/SideNavigation.test.tsx), please add a test that renders SideNavigation with ariaLabel set and asserts the <nav> has the expected aria-label attribute.
ac94a64 to
cd0ebf0
Compare
|
🎉 This PR is included in version 4.1.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Done
QA
Pinging @canonical/react-library-maintainers for a review.
Storybook
To see rendered examples of all react-components, run:
QA in your project
from
react-componentsrun:Install the resulting tarball in your project with:
QA steps
Create a dummy page that uses the SideNav and use it like this (for example):
Percy steps
Fixes
Fixes: #AC-4119.