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

v3.9 is out.

Navigation

ContextMenu

Free22.7 KB gzipped

Accessibility: WCAG 2.2 AA · No A or AA violations in light or dark mode · Keys: Shift+F10, Menu, Arrow Down and 9 more · Full report

Import

tsx
import { ContextMenu } from "@vjdesigns/vjdesigns-ui";

Importing only ContextMenu adds about 22.7 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

Basic

Right-click the card, long-press it on a touch screen, or focus it and press Shift+F10 (or the Menu key). It's a Menu in every other way. Right-click menus are hard to discover, so offer the same actions somewhere visible too.

Game film: Oct 18

Right-click or press Shift+F10 for actions

tsx
import { Card, ContextMenu, Text } from "@vjdesigns/vjdesigns-ui";

export function Basic() {
  return (
    <ContextMenu>
      <ContextMenu.Trigger>
        <Card tabIndex={0} variant="outline" padding="lg" style={{ width: "100%", maxWidth: "20rem" }}>
          <Text weight="semibold">Game film: Oct 18</Text>
          <Text size="sm" tone="muted">
            Right-click or press Shift+F10 for actions
          </Text>
        </Card>
      </ContextMenu.Trigger>
      <ContextMenu.Content>
        <ContextMenu.Item>Rename</ContextMenu.Item>
        <ContextMenu.Item>Duplicate</ContextMenu.Item>
        <ContextMenu.Separator />
        <ContextMenu.Item tone="danger">Delete</ContextMenu.Item>
      </ContextMenu.Content>
    </ContextMenu>
  );
}

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.

Basic

Game film: Oct 18

Right-click or press Shift+F10 for actions

tsx
import { LocaleProvider } from "@vjdesigns/vjdesigns-ui";
import ar from "@vjdesigns/vjdesigns-ui/locales/ar";

// Basic is the "Basic" example above.
<LocaleProvider locale="ar" messages={ar}>
  <Basic />
</LocaleProvider>

API reference

ContextMenu

New in 1.5.0
ContextMenu props
PropTypeDefault
children

ContextMenu.Trigger and ContextMenu.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 its submenus.

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

Default for every item's closeOnSelect. When unset, plain items close the menu on selection; checkbox and radio items keep it open.

boolean—
disabled

Turns the custom menu off, so the browser's own context menu shows.

booleanfalse
longPressDelay

How long a touch must be held to open the menu, in ms.

number500

ContextMenu.Trigger

New in 1.5.0
ContextMenu.Trigger props
PropTypeDefault
children

The area that answers right-clicks: plain content (wrapped in a div) or a single element.

ReactNode—
asChild

Clone the single child instead of wrapping it in a div. The child must accept ref, className, and the pointer, context menu, and key handlers.

booleanfalse

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

ContextMenu.Content

New in 1.5.0
ContextMenu.Content props
PropTypeDefault
aria-label

Accessible name of the menu. Defaults to "Context menu" (translated); name it after what it acts on when you can ("Game film actions").

string—
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 standard HTML attributes, plus className, style and ref.

ContextMenu.Item

New in 1.5.0
ContextMenu.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.

ContextMenu.CheckboxItem

New in 1.5.0
ContextMenu.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.

ContextMenu.RadioGroup

New in 1.5.0
ContextMenu.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.

ContextMenu.RadioItem

New in 1.5.0
ContextMenu.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.

ContextMenu.Group

New in 1.5.0

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

ContextMenu.Label

New in 1.5.0

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

ContextMenu.Separator

New in 1.5.0

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

ContextMenu.Sub

New in 1.5.0
ContextMenu.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—

ContextMenu.SubTrigger

New in 1.5.0
ContextMenu.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.

ContextMenu.SubContent

New in 1.5.0
ContextMenu.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

ContextMenu 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
Shift+F10MenuWith focus inside the trigger area: opens the menu next to the focused element, on its first item.
Arrow DownArrow UpNext or previous item, wrapping.
HomeEndFirst or last item.
TypingMoves to the next item that starts with the typed characters.
EnterSpaceActivates the item.
Arrow RightArrow LeftOpens or closes a submenu (mirrored right to left).
EscapeCloses the menu; focus goes back to where it was.
TabCloses the menu.

Right-click menus are hard to discover and some assistive technology never opens them: offer the same actions somewhere visible too. Make the trigger area focusable so keyboard users can reach the menu.

Roles and states

Roles and states
ElementRoleStates and properties
Contentmenuaria-label ("Context menu", or your own)
Itemmenuitem / menuitemcheckbox / menuitemradioaria-checked, aria-disabled, as in Menu
Trigger areaIts ownThe element you wrap; it should be focusable

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)