An open source design system that's fully customizable and agent ready
TypeScript
fix(core): default an accessible name on the TopNav landmark (#3986)
Baraa Hamodi2331f220a863
diff --git a/.changeset/topnav-landmark-label.md b/.changeset/topnav-landmark-label.mdnew file mode 100644index 0000000000..52ce5f2dd1--- /dev/null+++ b/.changeset/topnav-landmark-label.md@@ -0,0 +1,6 @@+---+'@astryxdesign/core': patch+---++[fix] TopNav: the `<nav>` landmark now defaults its accessible name to "Top navigation" when the `label` prop is omitted, matching SideNav ("Side navigation"), Breadcrumbs, and Pagination. Previously an omitted `label` shipped an unnamed navigation landmark, leaving screen-reader users with multiple indistinguishable "navigation" landmarks on pages that compose SideNav + TopNav + Breadcrumbs. An explicit `label` still wins.+@bhamodidiff --git a/packages/core/src/TopNav/TopNav.doc.mjs b/packages/core/src/TopNav/TopNav.doc.mjsindex e8b5d79eb3..8498e94256 100644--- a/packages/core/src/TopNav/TopNav.doc.mjs+++ b/packages/core/src/TopNav/TopNav.doc.mjs@@ -109,6 +109,7 @@ export const docs = {name: 'label',type: 'string',description: 'Accessible label for the navigation landmark, applied as aria-label on the <nav> element.',+ default: "'Top navigation'",},{name: 'xstyle',diff --git a/packages/core/src/TopNav/TopNav.test.tsx b/packages/core/src/TopNav/TopNav.test.tsxindex 48c6a805fb..f8d17d67c0 100644--- a/packages/core/src/TopNav/TopNav.test.tsx+++ b/packages/core/src/TopNav/TopNav.test.tsx@@ -13,6 +13,7 @@ import {describe, it, expect, vi} from 'vitest';import {render, screen} from '@testing-library/react';import userEvent from '@testing-library/user-event';import {TopNav} from './TopNav';+import {TopNavRenderContext} from './TopNavRenderContext';import {TopNavHeading} from './TopNavHeading';import {NavIcon} from '../NavIcon';import {TopNavItem} from './TopNavItem';@@ -45,6 +46,35 @@ describe('TopNav', () => {);});+ it('defaults the landmark label to "Top navigation" when label is omitted', () => {+ render(<TopNav />);+ expect(+ screen.getByRole('navigation', {name: 'Top navigation'}),+ ).toBeInTheDocument();+ });++ it('defaults the landmark label in mobile-bar mode', () => {+ render(+ <TopNavRenderContext value="mobile-bar">+ <TopNav heading={<span>Logo</span>} />+ </TopNavRenderContext>,+ );+ expect(+ screen.getByRole('navigation', {name: 'Top navigation'}),+ ).toBeInTheDocument();+ });++ it('custom label overrides the default in mobile-bar mode', () => {+ render(+ <TopNavRenderContext value="mobile-bar">+ <TopNav label="Utility navigation" />+ </TopNavRenderContext>,+ );+ expect(+ screen.getByRole('navigation', {name: 'Utility navigation'}),+ ).toBeInTheDocument();+ });+it('renders heading slot content', () => {render(<TopNav heading={<span data-testid="title-content">Logo</span>} />);expect(screen.getByTestId('title-content')).toBeInTheDocument();diff --git a/packages/core/src/TopNav/TopNav.tsx b/packages/core/src/TopNav/TopNav.tsxindex 91ee0839cc..5133541f9f 100644--- a/packages/core/src/TopNav/TopNav.tsx+++ b/packages/core/src/TopNav/TopNav.tsx@@ -147,6 +147,7 @@ export interface TopNavProps extends BaseProps<HTMLElement> {/*** Accessible label for the navigation landmark.* Helps screen readers identify the navigation area.+ * @default 'Top navigation'*/label?: string;}@@ -176,7 +177,7 @@ export function TopNav({children,centerContent,endContent,- label,+ label = 'Top navigation',xstyle,className,style,@@ -294,9 +295,7 @@ export function TopNav({) : (endContent && (<div {...stylex.props(styles.endContent)}>- <TopNavSlotContext value="end">- {endContent}- </TopNavSlotContext>+ <TopNavSlotContext value="end">{endContent}</TopNavSlotContext></div>))}