Skip to content
Vertical Jump Designs-uiFront-End Studio
Get Pro

v3.9 is out.

Navigation

Menu

Free24.3 KB gzipped

Accessibility: 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

tsx
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

tsx
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.

tsx
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.

tsx
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.

tsx
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

tsx
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

Menu props
PropTypeDefault
children

Menu.Trigger and Menu.Content.

ReactNode—
open

Controlled open state.

boolean—
defaultOpen

Initial open state when uncontrolled.

booleanfalse
onOpenChange

Called with the next open state whenever it changes.

(open: boolean) => void—
size

Item height, padding, and type size for the menu and all its submenus.

"sm""md""lg""md"
closeOnSelect

Default for every item's closeOnSelect. When unset, plain items (Menu.Item) close the menu on selection, while checkbox and radio items keep it open so several can be toggled. An item's own closeOnSelect always wins.

boolean—

Menu.Trigger

Menu.Trigger props
PropTypeDefault
childrenRequired

A single element (usually a Button or IconButton) to turn into the trigger, or plain content to render inside a library Button.

ReactNode—
asChild

Clone the single child instead of wrapping it in a Button. Defaults to true when children is a single element. The child must be a focusable button that accepts ref, id, onClick, onKeyDown, and aria-*.

boolean—
variant

Visual style. Inherits from a surrounding ButtonGroup.

"solid""soft""outline""ghost""link""inverse""solid"
tone

Semantic color. Inherits from a surrounding ButtonGroup.

"neutral""primary""accent""success""warning""danger""info""primary"
size

Control height, padding, and type size. Inherits from a surrounding ButtonGroup.

"sm""md""lg""md"
radius

Corner rounding. When omitted, uses --control-radius (pill).

"none""xs""sm""md""lg""xl""2xl""pill""pill"
startIcon

Decorative icon before the label. Hidden from assistive technology.

ReactNode—
endIcon

Decorative icon after the label. Hidden from assistive technology.

ReactNode—
fullWidth

Stretches the button to fill its container. Inherits from a surrounding ButtonGroup.

booleanfalse

Also accepts native <button> attributes, plus className, style and ref.

Menu.Content

Menu.Content props
PropTypeDefault
children

Menu items, groups, separators, and submenus.

ReactNode—
placement

Preferred side and alignment relative to the trigger. Flips to the other side when there isn't room. On the top and bottom sides, start and end alignment follow the text direction: bottom-start lines up with the trigger's left edge in left-to-right layouts and its right edge in right-to-left ones.

"top""top-start""top-end""bottom""bottom-start""bottom-end""left""left-start""left-end""right""right-start""right-end""bottom-start"
offset

Gap between the trigger and the menu, in px.

number8
maxHeight

Maximum height (any CSS length, or px as a number). Longer menus scroll inside. Always capped to the viewport.

CSSProperties["maxHeight"]24rem
container

Element to portal into.

HTMLElement | nulldocument.body

Also accepts native <div> attributes, plus className, style and ref.

Menu.Item

Menu.Item props
PropTypeDefault
onSelect

Called when the item is chosen by click, Enter, or Space. Call event.preventDefault() to keep the menu open.

(event: MenuSelectEvent) => void—
tone

Semantic color. Use danger for destructive actions (pair it with a clear label or icon).

"neutral""danger""neutral"
shortcut

Keyboard shortcut hint shown at the end of the item, e.g. ["mod", "D"].

MenuShortcut—
closeOnSelect

Close the menu after selection. Defaults to the root closeOnSelect, then true.

boolean—
href

Render the item as a link (<a role="menuitem">) to this URL. Dropped while disabled.

string—
target

Link target, with href.

string—
rel

Link rel, with href.

string—
children

The item's label.

ReactNode—
disabled

Shows the item as unavailable. It stays focusable (aria-disabled) but can't be activated.

booleanfalse
icon

Decorative icon before the label. Hidden from assistive technology.

ReactNode—
textValue

Text used for typeahead when the label isn't plain text. Defaults to the label's text.

string—
ref

Ref to the item element (a div, or an a for link items).

Ref<HTMLElement>—

Also accepts standard HTML attributes, plus className, style and ref.

Menu.CheckboxItem

Menu.CheckboxItem props
PropTypeDefault
checked

Controlled checked state.

boolean—
defaultChecked

Initial checked state when uncontrolled.

booleanfalse
onCheckedChange

Called with the next checked state when the item is toggled.

(checked: boolean) => void—
onSelect

Called when the item is chosen, before it toggles. preventDefault() keeps the menu open (it already does by default).

(event: MenuSelectEvent) => void—
shortcut

Keyboard shortcut hint shown at the end of the item.

MenuShortcut—
closeOnSelect

Close the menu after toggling. Defaults to the root closeOnSelect, then false.

boolean—
children

The item's label.

ReactNode—
disabled

Shows the item as unavailable. It stays focusable (aria-disabled) but can't be activated.

booleanfalse
icon

Decorative icon before the label. Hidden from assistive technology.

ReactNode—
textValue

Text used for typeahead when the label isn't plain text. Defaults to the label's text.

string—
ref

Ref to the item element (a div, or an a for link items).

Ref<HTMLElement>—

Also accepts standard HTML attributes, plus className, style and ref.

Menu.RadioGroup

Menu.RadioGroup props
PropTypeDefault
value

Controlled selected value.

string—
defaultValue

Initial selected value when uncontrolled.

string—
onValueChange

Called with the newly selected value.

(value: string) => void—

Also accepts native <div> attributes, plus className, style and ref.

Menu.RadioItem

Menu.RadioItem props
PropTypeDefault
valueRequired

The value this item selects in its Menu.RadioGroup.

string—
onSelect

Called when the item is chosen, before the group value changes.

(event: MenuSelectEvent) => void—
shortcut

Keyboard shortcut hint shown at the end of the item.

MenuShortcut—
closeOnSelect

Close the menu after choosing. Defaults to the root closeOnSelect, then false.

boolean—
children

The item's label.

ReactNode—
disabled

Shows the item as unavailable. It stays focusable (aria-disabled) but can't be activated.

booleanfalse
icon

Decorative icon before the label. Hidden from assistive technology.

ReactNode—
textValue

Text used for typeahead when the label isn't plain text. Defaults to the label's text.

string—
ref

Ref to the item element (a div, or an a for link items).

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

Menu.Sub props
PropTypeDefault
children

A Menu.SubTrigger and a Menu.SubContent.

ReactNode—
onOpenChange

Called with the next open state whenever the submenu opens or closes.

(open: boolean) => void—

Menu.SubTrigger

Menu.SubTrigger props
PropTypeDefault
ref

Ref to the item element (a div, or an a for link items).

Ref<HTMLElement>—
disabled

Shows the item as unavailable. It stays focusable (aria-disabled) but can't be activated.

booleanfalse
children

The item's label.

ReactNode—
icon

Decorative icon before the label. Hidden from assistive technology.

ReactNode—
textValue

Text 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

Menu.SubContent props
PropTypeDefault
placement

Preferred side and alignment relative to the Menu.SubTrigger. Flips when there isn't room.

"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)
offset

Gap between the sub trigger and the submenu, in px.

number4
children

Menu items, groups, separators, and submenus.

ReactNode—
maxHeight

Maximum height (any CSS length, or px as a number). Longer menus scroll inside. Always capped to the viewport.

CSSProperties["maxHeight"]24rem
container

Element to portal into.

HTMLElement | nulldocument.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)

Running accessibility audit

Checking the examples above…

Lighthouse audit

Light mode

Score 100

35 passed · 0 failed · 30 not applicable · 10 to check by hand

Dark mode

Score 100

35 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

Keyboard
KeyAction
EnterSpaceArrow DownOn the trigger: opens the menu on the first item.
Arrow UpOn the trigger: opens the menu on the last item.
Arrow DownArrow UpNext or previous item, wrapping.
HomeEndFirst or last item. Page Up and Page Down do the same.
TypingMoves to the next item that starts with the typed characters.
EnterSpaceActivates the item (toggles checkbox and radio items).
Arrow RightOpens a submenu (mirrored right to left).
Arrow LeftCloses a submenu (mirrored right to left).
EscapeCloses the current level and returns focus to its trigger.
TabCloses 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

Roles and states
ElementRoleStates and properties
Triggerbuttonaria-haspopup="menu", aria-expanded, aria-controls
Contentmenuaria-labelledby → trigger
Itemmenuitemaria-disabled, aria-keyshortcuts
Checkbox / radio itemmenuitemcheckbox / menuitemradioaria-checked
Menu.Group / Menu.Separatorgroup / separator—
Menu.SubTriggermenuitemaria-haspopup="menu", aria-expanded

Manual checks

Automated tools find roughly a third of accessibility issues. Test these in your app, with your content.

Manual accessibility checks
CheckWhat to testWCAG 2.2
KeyboardEvery 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)
FocusFocus 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 readersNames, 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)
ColorMeaning 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 reflowAt 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 targetsClick 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)
MotionAnimations respect the reduced-motion setting.2.3.3 (AAA)