Navigation
ContextMenu
Free22.7 KB gzippedAccessibility: 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
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
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
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| 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 its submenus. | "sm""md""lg" | "md" |
closeOnSelectDefault for every item's | boolean | — |
disabledTurns the custom menu off, so the browser's own context menu shows. | boolean | false |
longPressDelayHow long a touch must be held to open the menu, in ms. | number | 500 |
ContextMenu.Trigger
New in 1.5.0| Prop | Type | Default |
|---|---|---|
childrenThe area that answers right-clicks: plain content (wrapped in a | ReactNode | — |
asChildClone the single child instead of wrapping it in a | boolean | false |
Also accepts native <div> attributes, plus className, style and ref.
ContextMenu.Content
New in 1.5.0| Prop | Type | Default |
|---|---|---|
aria-labelAccessible name of the menu. Defaults to "Context menu" (translated); name it after what it acts on when you can ("Game film actions"). | string | — |
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 standard HTML attributes, plus className, style and ref.
ContextMenu.Item
New in 1.5.0| 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.
ContextMenu.CheckboxItem
New in 1.5.0| 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.
ContextMenu.RadioGroup
New in 1.5.0| 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.
ContextMenu.RadioItem
New in 1.5.0| 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.
ContextMenu.Group
New in 1.5.0Also accepts standard HTML attributes, plus className, style and ref.
ContextMenu.Label
New in 1.5.0Also accepts standard HTML attributes, plus className, style and ref.
ContextMenu.Separator
New in 1.5.0Also accepts native <div> attributes, plus className, style and ref.
ContextMenu.Sub
New in 1.5.0| Prop | Type | Default |
|---|---|---|
childrenA | ReactNode | — |
onOpenChangeCalled with the next open state whenever the submenu opens or closes. | (open: boolean) => void | — |
ContextMenu.SubTrigger
New in 1.5.0| 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.
ContextMenu.SubContent
New in 1.5.0| 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
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)
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 |
|---|---|
| Shift+F10Menu | With focus inside the trigger area: opens the menu next to the focused element, on its first item. |
| Arrow DownArrow Up | Next or previous item, wrapping. |
| HomeEnd | First or last item. |
| Typing | Moves to the next item that starts with the typed characters. |
| EnterSpace | Activates the item. |
| Arrow RightArrow Left | Opens or closes a submenu (mirrored right to left). |
| Escape | Closes the menu; focus goes back to where it was. |
| Tab | Closes 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
| Element | Role | States and properties |
|---|---|---|
| Content | menu | aria-label ("Context menu", or your own) |
| Item | menuitem / menuitemcheckbox / menuitemradio | aria-checked, aria-disabled, as in Menu |
| Trigger area | Its own | The 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.
| 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) |