Context Menu
A wrapper for Base UI Context Menu — same items API as Menu, triggered by right-click on any element.
Default
Groups, submenus, separators
Right-click here
Checkbox
Indicator right (default)
Right-click here
Indicator left
Right-click here
With group labels
Right-click here
Radio
Controlled
Right-click here
Indicator left
Right-click here
With group labels
Right-click here
Installation
npx shadcn@latest add @glrk-ui/context-menuIf you haven't set up the prerequisites yet, check out registry setup.
Usage
Basic
import { ContextWrapper } from "@/components/ui/context-menu-wrapper"
<ContextWrapper items={["Cut", "Copy", "Paste"]}>
<div className="border border-dashed rounded-lg p-8">
Right-click here
</div>
</ContextWrapper>With shortcuts and destructive item
<ContextWrapper
items={[
{ label: "Edit", value: "edit", shortcut: "⌘E" },
{ label: "Delete", value: "delete", variant: "destructive", shortcut: "⌘⌫" },
]}
onSelect={v => console.log(v)}
>
<div>Right-click here</div>
</ContextWrapper>Checkbox
const [checked, setChecked] = useState<allowedPrimitiveT[]>([])
<ContextCheckboxWrapper
items={["Auto-save", "Spellcheck", "Dark mode"]}
checked={checked}
onCheckedChange={(v, c) =>
setChecked(prev => (c ? [...prev, v] : prev.filter(x => x !== v)))
}
>
<div>Right-click here</div>
</ContextCheckboxWrapper>Radio
const [val, setVal] = useState<allowedPrimitiveT>("Light")
<ContextRadioWrapper
items={["Light", "Dark", "System"]}
value={val}
onValueChange={setVal}
>
<div>Right-click here</div>
</ContextRadioWrapper>Indicator position
<ContextCheckboxWrapper items={items} indicatorAt="right">
<div>Right-click here</div>
</ContextCheckboxWrapper>Groups, submenus, separators
const items: menuItemsT = [
{ label: "Cut", value: "cut", shortcut: "⌘X" },
{ label: "Copy", value: "copy", shortcut: "⌘C" },
"---",
{
group: "Actions",
items: ["Save", "Export"],
},
{
submenu: "Share",
items: ["Email", "Link"],
},
]Reference
ContextWrapper
Prop
Type
ContextCheckboxWrapper
Prop
Type
ContextRadioWrapper
Prop
Type
Related Components
- Base UI Context Menu
- Shadcn Context Menu
- Menu — same items API, triggered by click