Skip to content
Open
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/user-menu-keyboard.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@hyperdx/app': patch
---

fix: make the side nav's user menu reachable from the keyboard. Its trigger was
a plain <div>, so Tab skipped it and Enter and Space did nothing: keyboard users
could not open User preferences or Log out. It is now a <button>, named with the
user's name when the nav is collapsed to the avatar, with no visual change.
9 changes: 8 additions & 1 deletion packages/app/src/components/AppNav/AppNav.components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,23 @@ export const AppNavUserMenu = ({
return (
<Menu position="top-start" transitionProps={{ transition: 'fade-up' }}>
<Menu.Target>
{/* A real <button> so keyboard users can reach and open the menu; a
<div> trigger is skipped by Tab and ignores Enter and Space. */}
<Paper
component="button"
type="button"
data-testid="user-menu-trigger"
className={cx(styles.userMenu, {
[styles.userMenuCollapsed]: isCollapsed,
})}
>
<Group gap="xs" wrap="nowrap" miw={0}>
<Avatar size="sm" radius="xl" color="gray">
{/* The initials repeat the name, so screen readers skip them. */}
<Avatar size="sm" radius="xl" color="gray" aria-hidden>
{initials}
</Avatar>
{/* Collapsed, only the initials show; name the button in full. */}
{isCollapsed && <VisuallyHidden>{displayName}</VisuallyHidden>}
{!isCollapsed && (
<>
<Tooltip
Expand Down
17 changes: 15 additions & 2 deletions packages/app/src/components/AppNav/AppNav.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,16 @@ $transition-slow: 0.2s ease;

.userMenu {
cursor: pointer;

// A <button>: unlike the <div> it replaced, it neither fills the row nor
// centres with auto margins unless it is a sized block, and it brings the
// browser's own border, font, colour and centred text.
display: block;
width: calc(100% - 2 * #{$spacing-sm});
border: 0;
font: inherit;
color: inherit;
text-align: left;
margin: $spacing-sm;
padding: $spacing-xs $spacing-sm;
border-radius: $radius-md;
Expand All @@ -520,7 +530,9 @@ $transition-slow: 0.2s ease;
max-width: 100%;
overflow: hidden;

&:hover {
&:hover,
&:focus-visible {
outline: none;
background: var(--color-bg-sidenav-link-active);
}

Expand All @@ -533,7 +545,8 @@ $transition-slow: 0.2s ease;
border: none !important;
width: fit-content;

&:hover {
&:hover,
&:focus-visible {
background: var(--color-bg-sidenav-link-active);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { MantineProvider } from '@mantine/core';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';

import {
AppNavContext,
AppNavUserMenu,
} from '@/components/AppNav/AppNav.components';

const renderUserMenu = (isCollapsed: boolean) =>
render(
<MantineProvider>
<AppNavContext value={{ isCollapsed, pathname: '/search' }}>
<AppNavUserMenu userName="Jane Doe" teamName="Acme" />
</AppNavContext>
</MantineProvider>,
);

describe('AppNavUserMenu', () => {
// The initials avatar is hidden from screen readers, so the name is the
// user's name (plus the team when expanded), not "JD Jane Doe".
it.each([
['expanded', 'Enter', false, 'Jane Doe Acme', '{Enter}'],
['expanded', 'Space', false, 'Jane Doe Acme', '[Space]'],
['collapsed', 'Enter', true, 'Jane Doe', '{Enter}'],
['collapsed', 'Space', true, 'Jane Doe', '[Space]'],
] as const)(
'opens from the keyboard when the nav is %s (%s)',
async (_state, _keyName, isCollapsed, name, key) => {
const user = userEvent.setup();
renderUserMenu(isCollapsed);

await user.tab();
const trigger = screen.getByRole('button', { name });
expect(trigger).toHaveFocus();

await user.keyboard(key);
expect(
await screen.findByRole('menuitem', { name: 'User preferences' }),
).toBeInTheDocument();
},
);
});
Loading