Browse documentation Components Actions Text inputs Choices Selection Date and time Feedback Overlays Navigation Layout Data display Media and files Brand Stable import { ContextMenu } from "@repo/ui/context-menu";Source Clique com o botão direito em “Contestação.pdf”
Right-click the area to open the menu. On a touch screen, press and hold. Use the arrow keys to move, Enter to choose and Escape to close.
When to use
As a shortcut for power users over a file, a tab or a row, such as “Excluir documento” on a document in a list.
When the same actions are already reachable from a visible control. The context menu is an extra path, never the only one.
For work on dense surfaces where adding a button to every item would clutter the page.
When not to use
The only way to reach an action. Nothing on the page tells the user it exists. Use a Dropdown menu behind a visible button.
Choosing a form value. Use Select .
A main action with alternatives. Use Button menu .
Searching actions. Use Command .
Touch-first pages. Long press is slow and not discoverable. Offer a visible button.
Which one to use
Component
Opens with
Holds
Discoverable
Use for
Dropdown menu
A button
Actions, toggles, radio options
Yes
Actions on an item, view settings
Context menu
Right click, long press
The same kinds of items
No
Shortcuts on an area
Button menu
A split button
Alternatives to the main action
Yes
“Enviar para revisão” and variations
Select
A field
Values, one chosen
Yes
Form fields
Command
A search field
Actions and pages, filtered
Yes
Global search and shortcuts
Anatomy
Part
Role
ContextMenu
Holds the open state.
ContextMenuTrigger
The area the user right-clicks. Renders a span. Give it a size and a border.
ContextMenuContent
The popup, rendered in a portal at the pointer.
ContextMenuItem
One action. 44px tall.
ContextMenuCheckboxItem
An on/off option with a check on the right.
ContextMenuRadioGroup, ContextMenuRadioItem
One option out of several, with a dot on the right.
ContextMenuLabel, ContextMenuGroup, ContextMenuSeparator
Headings, groups and dividers.
ContextMenuShortcut
Right-aligned hint of a keyboard shortcut. It does not bind the keys.
ContextMenuSub, ContextMenuSubTrigger, ContextMenuSubContent
A nested menu opened from an item with a chevron.
Examples
Actions on an area
Clique com o botão direito em “Contestação.pdf”
Toggle selection
Clique com o botão direito em “Petição inicial.pdf”
Checkbox and radio items
Clique com o botão direito na tarefa “Revisar contestação”
Clique com o botão direito na tarefa “Revisar contestação”
Content
Start each item with a verb: “Abrir documento”, “Copiar nome do arquivo”.
Keep the list short. Past about 7 items, group them with separators or use a submenu.
Show the same items, in the same order and with the same labels, as the visible menu of the same surface.
Put destructive actions last, after a separator.
Accessibility
Built on Radix Context Menu. The popup has role="menu" and items have menuitem, menuitemcheckbox or menuitemradio, with aria-checked on the last two.
Opening: right click, or a long press on touch. A keyboard opens it with the browser’s own context menu keys (Menu key or Shift+F10) on a focused element, because Radix listens to the contextmenu event. The trigger is a plain span and is not focusable by default, so make something inside it focusable, or provide the same actions through a button.
Once open, keyboard behavior matches Dropdown menu: arrows move, Home and End jump, letters jump to an item, Enter or Space chooses, ArrowRight opens a submenu, ArrowLeft closes it, Escape closes the menu.
The area gives no hint that a menu exists. Never make the context menu the only path to an action.
Items are 44px tall, above the 24px minimum hit target. Disabled items carry aria-disabled and are skipped by arrow keys.
While open, the menu is modal: the page behind is inert. Pass modal={false} to change it.
Code
import {
ContextMenu,
ContextMenuContent,
ContextMenuItem,
ContextMenuSeparator,
ContextMenuTrigger,
} from "@repo/ui/context-menu" ;
< ContextMenu >
< ContextMenuTrigger asChild >
< div tabIndex = { 0 }>Contestação.pdf</ div >
</ ContextMenuTrigger >
< ContextMenuContent className = "w-64" >
< ContextMenuItem onSelect = {handleOpen}>Abrir documento</ ContextMenuItem >
< ContextMenuItem onSelect = {handleCopy}>
Copiar nome do arquivo
</ ContextMenuItem >
< ContextMenuSeparator />
< ContextMenuItem onSelect = {handleDelete}>Excluir documento</ ContextMenuItem >
</ ContextMenuContent >
</ ContextMenu >;
Props
ContextMenuProp Type Default Description dir"ltr" | "rtl"—Reading direction of the menu modalbooleantrueBlocks interaction with the rest of the page while open onOpenChange(open: boolean) => void—Called when the menu opens or closes
ContextMenuTriggerProp Type Default Description asChildbooleanfalseRenders the child element as the trigger area instead of a span. disabledbooleanfalseLets the browser show its own context menu instead.
ContextMenuContentProp Type Default Description alignOffsetnumber0Offset from the pointer along the alignment axis. loopbooleanfalseWraps keyboard focus from the last item to the first. onEscapeKeyDown(event: KeyboardEvent) => void—Called when `Escape` is pressed. Call `event.preventDefault()` to keep the menu open.
ContextMenuItemProp Type Default Description onSelect(event: Event) => void—Called when the item is chosen. The menu closes afterwards unless you call `event.preventDefault()`. disabledbooleanfalsePrevents choosing the item. insetbooleanfalseAdds left padding to align with items that have an indicator. Also on ContextMenuLabel and ContextMenuSubTrigger.
ContextMenuCheckboxItemProp Type Default Description checkedboolean | 'indeterminate'—Controlled checked state. onCheckedChange(checked: boolean) => void—Called when the user toggles the item.
ContextMenuRadioGroup, ContextMenuRadioItemProp Type Default Description valuestring—On ContextMenuRadioGroup: the selected value. On ContextMenuRadioItem: the value of the option. onValueChange(value: string) => void—On ContextMenuRadioGroup: called when the user picks an option.
Known issues
Issue
Effect
ContextMenuTrigger renders a span with no tabIndex.
Keyboard users cannot reach the menu unless the app makes the area focusable.
Disabled items use data-[disabled]:opacity-50.
The repository avoids opacity-based disabled states, and the label contrast drops below the AA minimum.
The popup shadow is the hardcoded shadow-[0px_25px_25px_rgba(0,0,0,0.15)].
A raw color value outside the token system, and translucent.
Unlike DropdownMenuContent, ContextMenuContent has no container prop.
The popup always renders in the document body, which matters for isolated previews and shadow roots.
Items and labels use raw text-sm and text-xs classes instead of Typography.
The text does not follow the type scale tokens.
Previous
Condition editor row
Next
Creatable combobox Edit this page on GitHub