Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(sidenav): label product icon link with heading text (#3548)

Cindy Zhangf51e7b9b148d
diff --git a/.changeset/sidenav-heading-link-name.md b/.changeset/sidenav-heading-link-name.md
new file mode 100644
index 0000000000..ff7888ceb8
--- /dev/null
+++ b/.changeset/sidenav-heading-link-name.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] SideNavHeading: label the product icon link with the heading text so it has an accessible name. When superheadingHref, headingHref, and a menu were all set, the icon link to the heading href rendered with no text or aria-label, so axe flagged it under link-name and screen readers announced an unlabeled link. (#3343)
+
+@cixzhang
diff --git a/packages/core/src/SideNav/SideNav.test.tsx b/packages/core/src/SideNav/SideNav.test.tsx
index 259b58cab7..bb32f7722a 100644
--- a/packages/core/src/SideNav/SideNav.test.tsx
+++ b/packages/core/src/SideNav/SideNav.test.tsx
@@ -234,6 +234,38 @@ describe('SideNavHeading', () => {
expect(links[1]).toHaveAttribute('href', '/product');
});
+ it('gives every link an accessible name with superheadingHref, headingHref, and menu', () => {
+ render(
+ <SideNavHeading
+ icon={<span>Icon</span>}
+ superheading="Suite Name"
+ superheadingHref="/suite"
+ heading="Product Name"
+ headingHref="/product"
+ menu={<div>Analytics</div>}
+ />,
+ );
+ // The icon link to /product previously rendered with no text and no
+ // aria-label, producing an empty accessible name (axe rule: link-name).
+ // Every link pointing at /product must now expose "Product Name".
+ const productLinks = screen
+ .getAllByRole('link', {name: 'Product Name'})
+ .filter(link => link.getAttribute('href') === '/product');
+ expect(productLinks.length).toBeGreaterThan(0);
+ for (const link of productLinks) {
+ expect(link).toHaveAccessibleName('Product Name');
+ }
+ // The independent superheading link is unaffected.
+ expect(screen.getByRole('link', {name: 'Suite Name'})).toHaveAttribute(
+ 'href',
+ '/suite',
+ );
+ // No link should be missing an accessible name.
+ for (const link of screen.getAllByRole('link')) {
+ expect(link).toHaveAccessibleName();
+ }
+ });
+
it('shows chevron when menu is provided', () => {
render(<SideNavHeading heading="My App" menu={<div>Menu content</div>} />);
// The chevron SVG should be rendered
diff --git a/packages/core/src/SideNav/SideNavHeading.tsx b/packages/core/src/SideNav/SideNavHeading.tsx
index 0ee4077e42..855959eeda 100644
--- a/packages/core/src/SideNav/SideNavHeading.tsx
+++ b/packages/core/src/SideNav/SideNavHeading.tsx
@@ -652,7 +652,10 @@ export function SideNavHeading({
)}>
{icon &&
(headingHref ? (
- <LinkComponent href={headingHref} {...stylex.props(styles.icon)}>
+ <LinkComponent
+ href={headingHref}
+ aria-label={heading}
+ {...stylex.props(styles.icon)}>
{icon}
</LinkComponent>
) : (
@@ -709,7 +712,10 @@ export function SideNavHeading({
{...props}>
{icon &&
(headingHref ? (
- <LinkComponent href={headingHref} {...stylex.props(styles.icon)}>
+ <LinkComponent
+ href={headingHref}
+ aria-label={heading}
+ {...stylex.props(styles.icon)}>
{icon}
</LinkComponent>
) : (