Skip to content
Draft
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.
6 changes: 6 additions & 0 deletions packages/app/src/components/AppNav/AppNav.components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,11 @@ 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,
Expand All @@ -133,6 +137,8 @@ export const AppNavUserMenu = ({
<Avatar size="sm" radius="xl" color="gray">
{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,39 @@
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', () => {
it.each([
['expanded', false],
['collapsed', true],
])(
'opens from the keyboard when the nav is %s',
async (_state, isCollapsed) => {
const user = userEvent.setup();
renderUserMenu(isCollapsed);

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

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