ContextMenu
A menu of actions on an object, opened with a right click, a long press or the context-menu key.
A context menu offers actions on the thing under the pointer: a file, a row, a card. It opens with a right click, a long press on a touch screen, or the keyboard's context-menu key. It offers shortcuts to actions, never the only way to them: many readers never right-click. Its parts and items are those of the dropdown menu.
Last action: nothing yet · not pinned
// apps/docs/examples/ui/context-menu.tsx'use client';
import {useState} from 'react';import {FileTextIcon} from 'lucide-react';
import { ContextMenu, ContextMenuCheckboxItem, ContextMenuContent, ContextMenuGroup, ContextMenuItem, ContextMenuLabel, ContextMenuSeparator, ContextMenuTrigger,} from '@workspace/active-ui/components/primitives/context-menu';
/** * Actions on an object, opened with a right click, a long press on a touch * screen, or the context-menu key. It repeats actions that are also reachable * elsewhere: a context menu alone is hidden from readers who do not know it * is there. */export default function ContextMenuExample() { const [last, setLast] = useState('nothing yet'); const [pinned, setPinned] = useState(false); return ( <div className="flex w-full max-w-sm flex-col items-center gap-4"> <ContextMenu> <ContextMenuTrigger className="border-border text-muted-foreground flex h-36 w-full flex-col items-center justify-center gap-2 rounded-md border border-dashed text-sm"> <FileTextIcon aria-hidden className="size-6" /> Statement 2026-Q3.pdf <span className="text-xs">Right-click or long-press</span> </ContextMenuTrigger> <ContextMenuContent className="w-52"> <ContextMenuGroup> <ContextMenuLabel>Statement 2026-Q3.pdf</ContextMenuLabel> <ContextMenuItem onClick={() => setLast('Open')}> Open </ContextMenuItem> <ContextMenuItem onClick={() => setLast('Download')}> Download </ContextMenuItem> </ContextMenuGroup> <ContextMenuCheckboxItem checked={pinned} onCheckedChange={setPinned}> Pin to the top </ContextMenuCheckboxItem> <ContextMenuSeparator /> <ContextMenuItem variant="destructive" onClick={() => setLast('Delete')} > Delete </ContextMenuItem> </ContextMenuContent> </ContextMenu> <p className="text-muted-foreground text-sm" aria-live="polite"> Last action: {last} · {pinned ? 'pinned' : 'not pinned'} </p> </div> );}Usage#
import { ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuTrigger,} from '@workspace/active-ui/components/primitives/context-menu';
<ContextMenu> <ContextMenuTrigger>Statement 2026-Q3.pdf</ContextMenuTrigger> <ContextMenuContent> <ContextMenuItem onClick={open}>Open</ContextMenuItem> </ContextMenuContent></ContextMenu>;Anatomy#
ContextandMenu Context: the area that opens the menu. The menu opens at the pointer.Menu Trigger ContextwithMenu Content Context(Menu Item variant,inset),Context,Menu Checkbox Item ContextwithMenu Radio Group Context,Menu Radio Item ContextwithMenu Group Context,Menu Label Contextwith its trigger and content,Menu Sub ContextandMenu Separator Context: as in the dropdown menu.Menu Shortcut
What your application provides#
The same actions somewhere visible, such as a button with a dropdown menu on the object.
What each item does.
Accessibility and keyboard#
The trigger area is not a tab stop of its own. When it, or an element inside it, has focus, the context-menu key or
Shift+F10opens the menu.Inside the menu, the keys of the dropdown menu apply;
Escapecloses it.
API#
ContextMenuItem#
Import from @workspace/
Props marked Base UI are behaviour of the Base UI part this component is built on.
Props
Events
Called by the component when something happens.
Other props, such as the standard attributes of the underlying element, className and ref, are passed through.
Other parts#
ContextMenu
All props come from the Base UI part this component is built on.
Props
Events
Called by the component when something happens.
Takes only the props listed.
ContextMenuContent
All props come from the Base UI part this component is built on.
Props
Other props, such as the standard attributes of the underlying element, className and ref, are passed through.
ContextMenuCheckboxItem
Props marked Base UI are behaviour of the Base UI part this component is built on.
Props
Events
Called by the component when something happens.
Other props, such as the standard attributes of the underlying element, className and ref, are passed through.
ContextMenuRadioItem
Props marked Base UI are behaviour of the Base UI part this component is built on.
Props
Events
Called by the component when something happens.
Other props, such as the standard attributes of the underlying element, className and ref, are passed through.
ContextMenuLabel
Props marked Base UI are behaviour of the Base UI part this component is built on.
Props
Other props, such as the standard attributes of the underlying element, className and ref, are passed through.
ContextMenuSeparator
All props come from the Base UI part this component is built on.
Props
Other props, such as the standard attributes of the underlying element, className and ref, are passed through.
ContextMenuGroup
All props come from the Base UI part this component is built on.
Props
Other props, such as the standard attributes of the underlying element, className and ref, are passed through.
ContextMenuPortal
All props come from the Base UI part this component is built on.
Props
Other props, such as the standard attributes of the underlying element, className and ref, are passed through.
ContextMenuSub
All props come from the Base UI part this component is built on.
Props
Events
Called by the component when something happens.
Takes only the props listed.
ContextMenuSubContent
All props come from the Base UI part this component is built on.
Props
Other props, such as the standard attributes of the underlying element, className and ref, are passed through.
ContextMenuSubTrigger
Props marked Base UI are behaviour of the Base UI part this component is built on.
Props
Events
Called by the component when something happens.
Other props, such as the standard attributes of the underlying element, className and ref, are passed through.
ContextMenuRadioGroup
All props come from the Base UI part this component is built on.
Props
Events
Called by the component when something happens.
Other props, such as the standard attributes of the underlying element, className and ref, are passed through.
Parts that take only their element’s attributes
This page adapts the Context Menu documentation of shadcn/ui (MIT licence) to this package; see Third-party notices.