diff --git a/.changeset/collapsed-nav-accessible-names.md b/.changeset/collapsed-nav-accessible-names.md new file mode 100644 index 000000000..85da5bb89 --- /dev/null +++ b/.changeset/collapsed-nav-accessible-names.md @@ -0,0 +1,8 @@ +--- +'@hyperdx/app': patch +--- + +fix: give the collapsed side nav's links an accessible name. With the nav +collapsed to icons, the page links and the logo link had no text, so screen +readers announced them only as "link". The labels now stay in the page, +visually hidden. diff --git a/packages/app/src/components/AppNav/AppNav.components.tsx b/packages/app/src/components/AppNav/AppNav.components.tsx index 462a8128d..ad20ba7a7 100644 --- a/packages/app/src/components/AppNav/AppNav.components.tsx +++ b/packages/app/src/components/AppNav/AppNav.components.tsx @@ -16,6 +16,7 @@ import { Text, Tooltip, UnstyledButton, + VisuallyHidden, } from '@mantine/core'; import { useDisclosure } from '@mantine/hooks'; import { @@ -33,6 +34,7 @@ import { IconUserCog, } from '@tabler/icons-react'; +import { useBrandDisplayName, useLogomark } from '@/brand'; import { IS_LOCAL_MODE } from '@/config'; import { useConnections } from '@/connection'; import { setHdxClickHouseVersions } from '@/hdxDebug'; @@ -55,6 +57,19 @@ export const AppNavContext = React.createContext<{ pathname: '/', }); +// The collapsed nav's logo. The mark is aria-hidden, so the brand name is kept +// for screen readers, or the logo link has no accessible name. +export const AppNavCollapsedLogo = () => { + const logomark = useLogomark({ size: 22 }); + const brandDisplayName = useBrandDisplayName(); + return ( +
+ {logomark} + {brandDisplayName} +
+ ); +}; + export const AppNavCloudBanner = () => { return (
@@ -414,7 +429,13 @@ export const AppNavLink = ({ > {icon} - {!isCollapsed && {label}} + {/* The collapsed rail shows only the icon. Keep the label for screen + readers, or the link has no accessible name. */} + {isCollapsed ? ( + {label} + ) : ( + {label} + )} {!isCollapsed && isBeta && ( { let redirectUrl; @@ -388,7 +388,7 @@ export default function AppNav({ fixed = false }: { fixed?: boolean }) { > {isCollapsed ? ( -
{logomark}
+ ) : ( + render( + + + } /> + + , + ); + +describe('AppNavLink', () => { + it('names the link with its label when the nav is expanded', () => { + renderLink(false); + expect(screen.getByRole('link', { name: 'Search' })).toBeInTheDocument(); + }); + + it('keeps the accessible name when the nav is collapsed to icons', () => { + renderLink(true); + expect(screen.getByRole('link', { name: 'Search' })).toBeInTheDocument(); + }); +}); + +describe('AppNavCollapsedLogo', () => { + it('names the logo link with the brand name', () => { + render( + + + + + , + ); + expect( + screen.getByRole('link', { name: BRAND_DISPLAY_NAME }), + ).toBeInTheDocument(); + }); +});