Navigation
Menu
Free24.3 KB gzippedAccessibility: WCAG 2.2 AA · No A or AA violations in light or dark mode · Keys: Enter, Space, Arrow Down and 7 more · Full report
Import
import { Menu } from "@vjdesigns/vjdesigns-ui";
Importing only Menu adds about 24.3 KB of minified, gzipped JavaScript to your app (React not included). The stylesheet is shared by every component and loaded once: 75.1 KB gzipped.
Examples
Actions
Arrow keys move between items, typing jumps to a match, and Escape closes and returns focus.
Last action: None
import { useState } from "react";
import {
ChevronDownIcon,
CopyIcon,
EditIcon,
Flex,
Menu,
Text,
TrashIcon,
} from "@vjdesigns/vjdesigns-ui";
export function Actions() {
const [last, setLast] = useState("None");
return (
<Flex gap={4} align="center">
<Menu>
<Menu.Trigger variant="outline" tone="neutral" endIcon={<ChevronDownIcon />}>
Actions
</Menu.Trigger>
<Menu.Content>
<Menu.Item icon={<EditIcon />} shortcut={["mod", "E"]} onSelect={() => setLast("Edit")}>
Edit
</Menu.Item>
<Menu.Item icon={<CopyIcon />} shortcut={["mod", "D"]} onSelect={() => setLast("Duplicate")}>
Duplicate
</Menu.Item>
<Menu.Separator />
<Menu.Item icon={<TrashIcon />} tone="danger" onSelect={() => setLast("Delete")}>
Delete
</Menu.Item>
</Menu.Content>
</Menu>
<Text size="sm" tone="muted">
Last action: {last}
</Text>
</Flex>
);
}
Options and submenus
Checkbox and radio items keep the menu's state; Menu.Sub nests a submenu.
import { useState } from "react";
import { IconButton, Menu, MoreHorizontalIcon } from "@vjdesigns/vjdesigns-ui";
export function OptionsAndSubmenus() {
const [sort, setSort] = useState("updated");
return (
<Menu>
<Menu.Trigger asChild>
<IconButton aria-label="View options" variant="soft" tone="neutral">
<MoreHorizontalIcon />
</IconButton>
</Menu.Trigger>
<Menu.Content>
<Menu.Group>
<Menu.Label>Show</Menu.Label>
<Menu.CheckboxItem defaultChecked>Completed tasks</Menu.CheckboxItem>
<Menu.CheckboxItem>Archived projects</Menu.CheckboxItem>
</Menu.Group>
<Menu.Separator />
<Menu.Group>
<Menu.Label>Sort by</Menu.Label>
<Menu.RadioGroup value={sort} onValueChange={setSort}>
<Menu.RadioItem value="updated">Last updated</Menu.RadioItem>
<Menu.RadioItem value="name">Name</Menu.RadioItem>
<Menu.RadioItem value="due">Due date</Menu.RadioItem>
</Menu.RadioGroup>
</Menu.Group>
<Menu.Separator />
<Menu.Sub>
<Menu.SubTrigger>Export as</Menu.SubTrigger>
<Menu.SubContent>
<Menu.Item>CSV</Menu.Item>
<Menu.Item>PDF</Menu.Item>
<Menu.Item>JSON</Menu.Item>
</Menu.SubContent>
</Menu.Sub>
</Menu.Content>
</Menu>
);
}
Accessibility
A WAI-ARIA menu button: the trigger opens the menu with Enter, Space or the arrow keys, the arrow keys move between items, and Escape closes it and returns focus to the trigger. Checkbox items expose aria-checked and show a check mark, so their state isn't color alone.
import { ChevronDownIcon, CopyIcon, Menu } from "@vjdesigns/vjdesigns-ui";
export function Accessibility() {
return (
<Menu>
<Menu.Trigger variant="outline" tone="neutral" endIcon={<ChevronDownIcon />}>
View
</Menu.Trigger>
<Menu.Content>
<Menu.CheckboxItem defaultChecked>Show sidebar</Menu.CheckboxItem>
<Menu.CheckboxItem>Show line numbers</Menu.CheckboxItem>
<Menu.Separator />
<Menu.Item icon={<CopyIcon />}>Copy link</Menu.Item>
</Menu.Content>
</Menu>
);
}
Translated
The menu opens in a layer elsewhere on the page but keeps the language of the area that opened it, so screen readers keep pronouncing it in German. The item labels are your own text.
import {
ChevronDownIcon,
CopyIcon,
EditIcon,
Menu,
TrashIcon,
LocaleProvider,
} from "@vjdesigns/vjdesigns-ui";
import de from "@vjdesigns/vjdesigns-ui/locales/de";
export function Translated() {
return (
<LocaleProvider locale="de" messages={de}>
<Menu>
<Menu.Trigger variant="outline" tone="neutral" endIcon={<ChevronDownIcon />}>
Bearbeiten
</Menu.Trigger>
<Menu.Content>
<Menu.Item icon={<EditIcon />}>Umbenennen</Menu.Item>
<Menu.Item icon={<CopyIcon />}>Duplizieren</Menu.Item>
<Menu.Separator />
<Menu.Item icon={<TrashIcon />} tone="danger">
Löschen
</Menu.Item>
</Menu.Content>
</Menu>
</LocaleProvider>
);
}
Right to left
The first example again, inside a right-to-left LocaleProvider (Arabic). Layout, spacing and arrow icons mirror, and the components' built-in text is translated. The example's own text stays in English.
Actions
Last action: None
import { LocaleProvider } from "@vjdesigns/vjdesigns-ui";
import ar from "@vjdesigns/vjdesigns-ui/locales/ar";
// Actions is the "Actions" example above.
<LocaleProvider locale="ar" messages={ar}>
<Actions />
</LocaleProvider>
API reference
Menu
| Prop | Type | Default |
|---|---|---|
children
| ReactNode | — |
openControlled open state. | boolean | — |
defaultOpenInitial open state when uncontrolled. | boolean | false |
onOpenChangeCalled with the next open state whenever it changes. | (open: boolean) => void | — |
sizeItem height, padding, and type size for the menu and all its submenus. | "sm""md""lg" | "md" |
closeOnSelectDefault for every item's | boolean | — |
Menu.Trigger
| Prop | Type | Default |
|---|---|---|
childrenRequiredA single element (usually a | ReactNode | — |
asChildClone the single child instead of wrapping it in a | boolean | — |
variantVisual style. Inherits from a surrounding | "solid""soft""outline""ghost""link""inverse" | "solid" |
toneSemantic color. Inherits from a surrounding | "neutral""primary""accent""success""warning""danger""info" | "primary" |
sizeControl height, padding, and type size. Inherits from a surrounding | "sm""md""lg" | "md" |
radiusCorner rounding. When omitted, uses | "none""xs""sm""md""lg""xl""2xl""pill" | "pill" |
startIconDecorative icon before the label. Hidden from assistive technology. | ReactNode | — |
endIconDecorative icon after the label. Hidden from assistive technology. | ReactNode | — |
fullWidthStretches the button to fill its container. Inherits from a surrounding | boolean | false |
Also accepts native <button> attributes, plus className, style and ref.
Menu.Content
| Prop | Type | Default |
|---|---|---|
childrenMenu items, groups, separators, and submenus. | ReactNode | — |
placementPreferred side and alignment relative to the trigger. Flips to the other side when there isn't room. On the top and bottom sides, | "top""top-start""top-end""bottom""bottom-start""bottom-end""left""left-start""left-end""right""right-start""right-end" | "bottom-start" |
offsetGap between the trigger and the menu, in px. | number | 8 |
maxHeightMaximum height (any CSS length, or px as a number). Longer menus scroll inside. Always capped to the viewport. | CSSProperties["maxHeight"] | 24rem |
containerElement to portal into. | HTMLElement | null | document.body |
Also accepts native <div> attributes, plus className, style and ref.
Menu.Item
| Prop | Type | Default |
|---|---|---|
onSelectCalled when the item is chosen by click, Enter, or Space. Call | (event: MenuSelectEvent) => void | — |
toneSemantic color. Use | "neutral""danger" | "neutral" |
shortcutKeyboard shortcut hint shown at the end of the item, e.g. | MenuShortcut | — |
closeOnSelectClose the menu after selection. Defaults to the root | boolean | — |
hrefRender the item as a link ( | string | — |
targetLink target, with | string | — |
relLink | string | — |
childrenThe item's label. | ReactNode | — |
disabledShows the item as unavailable. It stays focusable ( | boolean | false |
iconDecorative icon before the label. Hidden from assistive technology. | ReactNode | — |
textValueText used for typeahead when the label isn't plain text. Defaults to the label's text. | string | — |
refRef to the item element (a | Ref<HTMLElement> | — |
Also accepts standard HTML attributes, plus className, style and ref.
Menu.CheckboxItem
| Prop | Type | Default |
|---|---|---|
checkedControlled checked state. | boolean | — |
defaultCheckedInitial checked state when uncontrolled. | boolean | false |
onCheckedChangeCalled with the next checked state when the item is toggled. | (checked: boolean) => void | — |
onSelectCalled when the item is chosen, before it toggles. | (event: MenuSelectEvent) => void | — |
shortcutKeyboard shortcut hint shown at the end of the item. | MenuShortcut | — |
closeOnSelectClose the menu after toggling. Defaults to the root | boolean | — |
childrenThe item's label. | ReactNode | — |
disabledShows the item as unavailable. It stays focusable ( | boolean | false |
iconDecorative icon before the label. Hidden from assistive technology. | ReactNode | — |
textValueText used for typeahead when the label isn't plain text. Defaults to the label's text. | string | — |
refRef to the item element (a | Ref<HTMLElement> | — |
Also accepts standard HTML attributes, plus className, style and ref.
Menu.RadioGroup
| Prop | Type | Default |
|---|---|---|
valueControlled selected value. | string | — |
defaultValueInitial selected value when uncontrolled. | string | — |
onValueChangeCalled with the newly selected value. | (value: string) => void | — |
Also accepts native <div> attributes, plus className, style and ref.
Menu.RadioItem
| Prop | Type | Default |
|---|---|---|
valueRequiredThe value this item selects in its | string | — |
onSelectCalled when the item is chosen, before the group value changes. | (event: MenuSelectEvent) => void | — |
shortcutKeyboard shortcut hint shown at the end of the item. | MenuShortcut | — |
closeOnSelectClose the menu after choosing. Defaults to the root | boolean | — |
childrenThe item's label. | ReactNode | — |
disabledShows the item as unavailable. It stays focusable ( | boolean | false |
iconDecorative icon before the label. Hidden from assistive technology. | ReactNode | — |
textValueText used for typeahead when the label isn't plain text. Defaults to the label's text. | string | — |
refRef to the item element (a | Ref<HTMLElement> | — |
Also accepts standard HTML attributes, plus className, style and ref.
Menu.Group
Also accepts standard HTML attributes, plus className, style and ref.
Menu.Label
Also accepts standard HTML attributes, plus className, style and ref.
Menu.Separator
Also accepts native <div> attributes, plus className, style and ref.
Menu.Sub
| Prop | Type | Default |
|---|---|---|
childrenA | ReactNode | — |
onOpenChangeCalled with the next open state whenever the submenu opens or closes. | (open: boolean) => void | — |
Menu.SubTrigger
| Prop | Type | Default |
|---|---|---|
refRef to the item element (a | Ref<HTMLElement> | — |
disabledShows the item as unavailable. It stays focusable ( | boolean | false |
childrenThe item's label. | ReactNode | — |
iconDecorative icon before the label. Hidden from assistive technology. | ReactNode | — |
textValueText used for typeahead when the label isn't plain text. Defaults to the label's text. | string | — |
Also accepts standard HTML attributes, plus className, style and ref.
Menu.SubContent
| Prop | Type | Default |
|---|---|---|
placementPreferred side and alignment relative to the | "top""top-start""top-end""bottom""bottom-start""bottom-end""left""left-start""left-end""right""right-start""right-end" | "right-start" (or "left-start" in RTL) |
offsetGap between the sub trigger and the submenu, in px. | number | 4 |
childrenMenu items, groups, separators, and submenus. | ReactNode | — |
maxHeightMaximum height (any CSS length, or px as a number). Longer menus scroll inside. Always capped to the viewport. | CSSProperties["maxHeight"] | 24rem |
containerElement to portal into. | HTMLElement | null | document.body |
Also accepts standard HTML attributes, plus className, style and ref.
See what changed in each version in the Changelog.
Accessibility report
Menu targets WCAG 2.2 AA. Below: a live axe-core audit of this page's examples, Lighthouse scores for the page in both modes, the accessibility behavior built into the component, and the checks only a person can do.
axe-core audit (live)
Checking the examples above…
Lighthouse audit
Light mode
Score 10035 passed · 0 failed · 30 not applicable · 10 to check by hand
Dark mode
Score 10035 passed · 0 failed · 30 not applicable · 10 to check by hand
Lighthouse 13.5.0 audits the whole docs page (header and sidebar included), not just the examples, in English. Last run 11/27/2026. Some failed audits carry no weight in the score, so a page can score 100 and still list one.
Built-in behavior
Keyboard
| Key | Action |
|---|---|
| EnterSpaceArrow Down | On the trigger: opens the menu on the first item. |
| Arrow Up | On the trigger: opens the menu on the last item. |
| Arrow DownArrow Up | Next or previous item, wrapping. |
| HomeEnd | First or last item. Page Up and Page Down do the same. |
| Typing | Moves to the next item that starts with the typed characters. |
| EnterSpace | Activates the item (toggles checkbox and radio items). |
| Arrow Right | Opens a submenu (mirrored right to left). |
| Arrow Left | Closes a submenu (mirrored right to left). |
| Escape | Closes the current level and returns focus to its trigger. |
| Tab | Closes the whole menu and moves on from the trigger. |
One tab stop inside the menu (roving tabindex). Disabled items stay focusable but can't be activated.
Roles and states
| Element | Role | States and properties |
|---|---|---|
| Trigger | button | aria-haspopup="menu", aria-expanded, aria-controls |
| Content | menu | aria-labelledby → trigger |
| Item | menuitem | aria-disabled, aria-keyshortcuts |
| Checkbox / radio item | menuitemcheckbox / menuitemradio | aria-checked |
Menu.Group / Menu.Separator | group / separator | — |
Menu.SubTrigger | menuitem | aria-haspopup="menu", aria-expanded |
Manual checks
Automated tools find roughly a third of accessibility issues. Test these in your app, with your content.
| Check | What to test | WCAG 2.2 |
|---|---|---|
| Keyboard | Every action works with Tab, Shift+Tab, Enter, Space and the arrow keys, and focus never gets stuck. | 2.1.1 (A), 2.1.2 (A) |
| Focus | Focus moves in a logical order, is always visible, and isn't hidden behind sticky headers. | 2.4.3 (A), 2.4.7 (AA), 2.4.11 (AA), 2.4.13 (AAA) |
| Screen readers | Names, roles and states are announced correctly, and status changes are announced without moving focus. | 1.3.1 (A), 4.1.2 (A), 4.1.3 (AA) |
| Color | Meaning never depends on color alone; your own colors meet contrast in both modes. | 1.4.1 (A), 1.4.3 (AA), 1.4.11 (AA), 1.4.6 (AAA) |
| Zoom and reflow | At 200% text size and at 320px wide (400% zoom), nothing is cut off and no sideways scrolling is needed. | 1.4.4 (AA), 1.4.10 (AA), 1.4.12 (AA) |
| Pointer targets | Click and tap targets are at least 24×24px (44×44px for AAA), or spaced so they don't overlap. | 2.5.8 (AA), 2.5.5 (AAA) |
| Motion | Animations respect the reduced-motion setting. | 2.3.3 (AAA) |