Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/collapsed-nav-accessible-names.md
Original file line number Diff line number Diff line change
@@ -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.
23 changes: 22 additions & 1 deletion packages/app/src/components/AppNav/AppNav.components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
Text,
Tooltip,
UnstyledButton,
VisuallyHidden,
} from '@mantine/core';
import { useDisclosure } from '@mantine/hooks';
import {
Expand All @@ -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';
Expand All @@ -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 (
<div className={styles.logoIconWrapper}>
{logomark}
<VisuallyHidden>{brandDisplayName}</VisuallyHidden>
</div>
);
};

export const AppNavCloudBanner = () => {
return (
<div className="mt-3 mb-1 bg-muted rounded p-2 text-center">
Expand Down Expand Up @@ -414,7 +429,13 @@ export const AppNavLink = ({
>
<span className={styles.navItemContent}>
<span className={styles.navItemIcon}>{icon}</span>
{!isCollapsed && <span>{label}</span>}
{/* The collapsed rail shows only the icon. Keep the label for screen
readers, or the link has no accessible name. */}
{isCollapsed ? (
<VisuallyHidden>{label}</VisuallyHidden>
) : (
<span>{label}</span>
)}
</span>
{!isCollapsed && isBeta && (
<Badge
Expand Down
6 changes: 3 additions & 3 deletions packages/app/src/components/AppNav/AppNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
} from '@tabler/icons-react';

import api from '@/api';
import { useLogomark, useWordmark } from '@/brand';
import { useWordmark } from '@/brand';
import { AlertStatusIcon } from '@/components/AlertStatusIcon';
import { InstanceLabel } from '@/components/AppNav/InstanceLabel';
import { useMobileNavOverlay } from '@/components/AppNav/useMobileNavOverlay';
Expand All @@ -41,6 +41,7 @@ import {

import {
AppNavCloudBanner,
AppNavCollapsedLogo,
AppNavContext,
AppNavHelpMenu,
AppNavLink,
Expand Down Expand Up @@ -109,7 +110,6 @@ const NAV_LINKS: NavLinkConfig[] = [

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

useEffect(() => {
let redirectUrl;
Expand Down Expand Up @@ -388,7 +388,7 @@ export default function AppNav({ fixed = false }: { fixed?: boolean }) {
>
<Link href="/search" className={styles.logoLink}>
{isCollapsed ? (
<div className={styles.logoIconWrapper}>{logomark}</div>
<AppNavCollapsedLogo />
) : (
<Group
gap="xs"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import Link from 'next/link';
import { MantineProvider } from '@mantine/core';
import { IconSearch } from '@tabler/icons-react';
import { render, screen } from '@testing-library/react';

import { BRAND_DISPLAY_NAME } from '@/brand';
import {
AppNavCollapsedLogo,
AppNavContext,
AppNavLink,
} from '@/components/AppNav/AppNav.components';

const renderLink = (isCollapsed: boolean) =>
render(
<MantineProvider>
<AppNavContext value={{ isCollapsed, pathname: '/search' }}>
<AppNavLink label="Search" href="/search" icon={<IconSearch />} />
</AppNavContext>
</MantineProvider>,
);

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(
<MantineProvider>
<Link href="/search">
<AppNavCollapsedLogo />
</Link>
</MantineProvider>,
);
expect(
screen.getByRole('link', { name: BRAND_DISPLAY_NAME }),
).toBeInTheDocument();
});
});
Loading