Skip to content

Commit 4fce2f6

Browse files
authored
fix: name the collapsed side nav's links for screen readers (#3845)
## Summary Fixes #3844. With the side nav collapsed to icons, its links had no accessible name: `AppNavLink` dropped the label (`{!isCollapsed && <span>{label}</span>}`) and the collapsed logo link held only the `aria-hidden` logomark. Screen readers announced each one as "link". Lighthouse flags 7 of them on play-clickstack. - `AppNavLink` keeps its label when collapsed, inside Mantine's `VisuallyHidden`, so the link is named with no visual change. This works for any `ReactNode` label, not only strings. - The collapsed logo link gets the brand name from `useBrandDisplayName()` the same way. - New `AppNavLink.test.tsx` finds the link by role and name in both states; the collapsed case fails on `main` ("Unable to find an accessible element with the role "link" and name "Search""). - Changeset: `@hyperdx/app` patch. ### Screenshots or video No visual change: with the nav collapsed (`isNavCollapsed` = true, 1280x720, light theme), screenshots of the rail on `main` and on this branch are pixel-identical. What changes is the accessibility tree: | Before (`main`) | After (this branch) | | :----- | :---- | | Collapsed rail links: 7 with no name | `ClickStack`, `Search`, `Saved searches`, `Chart explorer`, `Client sessions`, `Service map`, `Dashboards` | | Lighthouse "Links do not have a discernible name": 7 failing | passes | ### How to reproduce **Starting point:** `yarn app:dev:local` + Connect to Demo Server, or https://play-clickstack.clickhouse.com/search for the "before". **On `main`:** 1. Collapse the side nav with the "Collapse/expand navigation" button. 2. In DevTools > Accessibility, inspect the Search link: it has no name. Lighthouse lists the logo link and 6 page links under "Links do not have a discernible name". **On this branch:** 1. Collapse the side nav the same way. 2. The Search link is named "Search" (and so on for each link; the logo link is named "ClickStack"). The Lighthouse audit passes. The rail looks the same as on `main`. ### How to test on Vercel preview **Preview routes:** /search **Steps:** 1. Click the button with aria-label "Collapse/expand navigation" to collapse the side nav. 2. Verify the link with data-testid "nav-link-search" has the accessible name "Search". 3. Verify the link with data-testid "nav-link-chart" has the accessible name "Chart explorer". ### References - Linear Issue: N/A - Related PRs: N/A --- > [!NOTE] > **Low Risk** > UI-only accessibility fix with no behavior, routing, or data changes; scoped to nav presentation and covered by new unit tests. > > **Overview** > When the side nav collapses to icons, **`AppNavLink`** no longer drops its label—it keeps the label in Mantine **`VisuallyHidden`** so each link still has an accessible name with no visible change. > > The collapsed logo link is handled by a new **`AppNavCollapsedLogo`** component that adds the brand display name via **`useBrandDisplayName()`** in **`VisuallyHidden`**, since the logomark alone is not announced. > > **`AppNav.tsx`** uses **`AppNavCollapsedLogo`** instead of inlining the logomark. New tests assert links are discoverable by role and name in both expanded and collapsed states. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 9d9e27b. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup>
1 parent dd3e6de commit 4fce2f6

4 files changed

Lines changed: 80 additions & 4 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'@hyperdx/app': patch
3+
---
4+
5+
fix: give the collapsed side nav's links an accessible name. With the nav
6+
collapsed to icons, the page links and the logo link had no text, so screen
7+
readers announced them only as "link". The labels now stay in the page,
8+
visually hidden.

‎packages/app/src/components/AppNav/AppNav.components.tsx‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
Text,
1717
Tooltip,
1818
UnstyledButton,
19+
VisuallyHidden,
1920
} from '@mantine/core';
2021
import { useDisclosure } from '@mantine/hooks';
2122
import {
@@ -33,6 +34,7 @@ import {
3334
IconUserCog,
3435
} from '@tabler/icons-react';
3536

37+
import { useBrandDisplayName, useLogomark } from '@/brand';
3638
import { IS_LOCAL_MODE } from '@/config';
3739
import { useConnections } from '@/connection';
3840
import { setHdxClickHouseVersions } from '@/hdxDebug';
@@ -55,6 +57,19 @@ export const AppNavContext = React.createContext<{
5557
pathname: '/',
5658
});
5759

60+
// The collapsed nav's logo. The mark is aria-hidden, so the brand name is kept
61+
// for screen readers, or the logo link has no accessible name.
62+
export const AppNavCollapsedLogo = () => {
63+
const logomark = useLogomark({ size: 22 });
64+
const brandDisplayName = useBrandDisplayName();
65+
return (
66+
<div className={styles.logoIconWrapper}>
67+
{logomark}
68+
<VisuallyHidden>{brandDisplayName}</VisuallyHidden>
69+
</div>
70+
);
71+
};
72+
5873
export const AppNavCloudBanner = () => {
5974
return (
6075
<div className="mt-3 mb-1 bg-muted rounded p-2 text-center">
@@ -414,7 +429,13 @@ export const AppNavLink = ({
414429
>
415430
<span className={styles.navItemContent}>
416431
<span className={styles.navItemIcon}>{icon}</span>
417-
{!isCollapsed && <span>{label}</span>}
432+
{/* The collapsed rail shows only the icon. Keep the label for screen
433+
readers, or the link has no accessible name. */}
434+
{isCollapsed ? (
435+
<VisuallyHidden>{label}</VisuallyHidden>
436+
) : (
437+
<span>{label}</span>
438+
)}
418439
</span>
419440
{!isCollapsed && isBeta && (
420441
<Badge

‎packages/app/src/components/AppNav/AppNav.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
} from '@tabler/icons-react';
2121

2222
import api from '@/api';
23-
import { useLogomark, useWordmark } from '@/brand';
23+
import { useWordmark } from '@/brand';
2424
import { AlertStatusIcon } from '@/components/AlertStatusIcon';
2525
import { InstanceLabel } from '@/components/AppNav/InstanceLabel';
2626
import { useMobileNavOverlay } from '@/components/AppNav/useMobileNavOverlay';
@@ -41,6 +41,7 @@ import {
4141

4242
import {
4343
AppNavCloudBanner,
44+
AppNavCollapsedLogo,
4445
AppNavContext,
4546
AppNavHelpMenu,
4647
AppNavLink,
@@ -109,7 +110,6 @@ const NAV_LINKS: NavLinkConfig[] = [
109110

110111
export default function AppNav({ fixed = false }: { fixed?: boolean }) {
111112
const wordmark = useWordmark();
112-
const logomark = useLogomark({ size: 22 });
113113

114114
useEffect(() => {
115115
let redirectUrl;
@@ -388,7 +388,7 @@ export default function AppNav({ fixed = false }: { fixed?: boolean }) {
388388
>
389389
<Link href="/search" className={styles.logoLink}>
390390
{isCollapsed ? (
391-
<div className={styles.logoIconWrapper}>{logomark}</div>
391+
<AppNavCollapsedLogo />
392392
) : (
393393
<Group
394394
gap="xs"
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import Link from 'next/link';
2+
import { MantineProvider } from '@mantine/core';
3+
import { IconSearch } from '@tabler/icons-react';
4+
import { render, screen } from '@testing-library/react';
5+
6+
import { BRAND_DISPLAY_NAME } from '@/brand';
7+
import {
8+
AppNavCollapsedLogo,
9+
AppNavContext,
10+
AppNavLink,
11+
} from '@/components/AppNav/AppNav.components';
12+
13+
const renderLink = (isCollapsed: boolean) =>
14+
render(
15+
<MantineProvider>
16+
<AppNavContext value={{ isCollapsed, pathname: '/search' }}>
17+
<AppNavLink label="Search" href="/search" icon={<IconSearch />} />
18+
</AppNavContext>
19+
</MantineProvider>,
20+
);
21+
22+
describe('AppNavLink', () => {
23+
it('names the link with its label when the nav is expanded', () => {
24+
renderLink(false);
25+
expect(screen.getByRole('link', { name: 'Search' })).toBeInTheDocument();
26+
});
27+
28+
it('keeps the accessible name when the nav is collapsed to icons', () => {
29+
renderLink(true);
30+
expect(screen.getByRole('link', { name: 'Search' })).toBeInTheDocument();
31+
});
32+
});
33+
34+
describe('AppNavCollapsedLogo', () => {
35+
it('names the logo link with the brand name', () => {
36+
render(
37+
<MantineProvider>
38+
<Link href="/search">
39+
<AppNavCollapsedLogo />
40+
</Link>
41+
</MantineProvider>,
42+
);
43+
expect(
44+
screen.getByRole('link', { name: BRAND_DISPLAY_NAME }),
45+
).toBeInTheDocument();
46+
});
47+
});

0 commit comments

Comments
 (0)