A right-click, long-press and Shift+F10 menu with submenus, checkbox and radio items, shortcut hints and a destructive style, built on Radix.
What changed
- 1.0.1 Oct 11, 2026Control heights, menu and sidebar row sizes, press dimming and frosted surfaces follow the platform feel tokens (--bm-control-h, --bm-menu-*, --bm-sidebar-*, --bm-material-*). Unchanged without a feel.
- 1.0.0 Sep 30, 2026First release.
Q3 roadmap.pdf
Right-click, long-press or Shift+F10
"use client";
import { Copy, ExternalLink, FileText, Pencil, Star, Trash2 } from "lucide-react";
import {
ContextMenu,
ContextMenuContent,
ContextMenuItem,
ContextMenuSeparator,
ContextMenuShortcut,
ContextMenuSub,
ContextMenuSubContent,
ContextMenuSubTrigger,
ContextMenuTrigger,
} from "@/components/ballmac/context-menu";
export default function ContextMenuDemo() {
return (
<ContextMenu>
<ContextMenuTrigger
tabIndex={0}
aria-label="Q3 roadmap.pdf. Right-click or press Shift+F10 for actions"
className="flex w-full max-w-sm items-center gap-3 rounded-xl border bg-card p-4 shadow-sm outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50"
>
<span className="flex size-11 items-center justify-center rounded-lg bg-muted">
<FileText aria-hidden="true" className="size-5" />
</span>
<div className="min-w-0 flex-1">
<p className="truncate text-sm font-semibold">Q3 roadmap.pdf</p>
<p className="text-xs text-muted-foreground">
Right-click, long-press or Shift+F10
</p>
</div>
</ContextMenuTrigger>
<ContextMenuContent className="w-56">
<ContextMenuItem>
<ExternalLink aria-hidden="true" /> Open
<ContextMenuShortcut>↵</ContextMenuShortcut>
</ContextMenuItem>
<ContextMenuItem>
<Pencil aria-hidden="true" /> Rename
<ContextMenuShortcut>F2</ContextMenuShortcut>
</ContextMenuItem>
<ContextMenuSub>
<ContextMenuSubTrigger>
<Copy aria-hidden="true" /> Copy as
</ContextMenuSubTrigger>
<ContextMenuSubContent>
<ContextMenuItem>Link</ContextMenuItem>
<ContextMenuItem>Markdown</ContextMenuItem>
</ContextMenuSubContent>
</ContextMenuSub>
<ContextMenuItem>
<Star aria-hidden="true" /> Add to favorites
</ContextMenuItem>
<ContextMenuSeparator />
<ContextMenuItem destructive>
<Trash2 aria-hidden="true" /> Move to trash
<ContextMenuShortcut>⌫</ContextMenuShortcut>
</ContextMenuItem>
</ContextMenuContent>
</ContextMenu>
);
}Installation
The default, and what a Radix-style project installs.
$ pnpm dlx shadcn@latest add @ballmac/context-menuInstall the dependencies.
$ pnpm add radix-ui lucide-reactAdd the Ballmac items it builds on.
$ pnpm dlx shadcn@latest add @ballmac/directionCopy the source into your project.
components/ballmac/context-menu.tsx// Ballmac UI: Context Menu. https://ui.ballmac.com/components/context-menu // Based on shadcn/ui Context Menu (MIT, Copyright (c) 2023 shadcn), restyled with tokens, destructive and inset items, and a shortcut slot. "use client"; import * as React from "react"; import { Check, ChevronRight, Circle } from "lucide-react"; import { ContextMenu as Primitive } from "radix-ui"; import { useDirection } from "@/lib/ballmac/direction"; import { cn } from "@/lib/utils"; const itemBase = "relative flex min-h-[var(--bm-menu-item-h,2rem)] cursor-default select-none items-center gap-2 rounded-[var(--bm-menu-item-radius,var(--radius-md))] px-2 py-1.5 text-sm outline-none transition-colors data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[highlighted]:bg-accent data-[highlighted]:text-accent-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground"; const surface = "z-50 min-w-[12rem] overflow-hidden rounded-xl border bg-popover/[var(--bm-material-alpha,100%)] backdrop-blur-[var(--bm-material-blur,0px)] p-[var(--bm-menu-pad,0.25rem)] text-popover-foreground shadow-[var(--bm-shadow-popover,0_12px_36px_-10px_rgb(0_0_0/0.25))] data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=open]:fade-in-0 data-[state=closed]:fade-out-0 data-[state=open]:zoom-in-95 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=top]:slide-in-from-bottom-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 motion-reduce:animate-none"; type ContextMenuProps = React.ComponentProps<typeof Primitive.Root>; function ContextMenu(props: ContextMenuProps) { const dir = useDirection(props.dir); return <Primitive.Root data-slot="context-menu" dir={dir} {...props} />; } type ContextMenuTriggerProps = React.ComponentProps<typeof Primitive.Trigger>; function ContextMenuTrigger(props: ContextMenuTriggerProps) { return <Primitive.Trigger data-slot="context-menu-trigger" {...props} />; } type ContextMenuGroupProps = React.ComponentProps<typeof Primitive.Group>; function ContextMenuGroup(props: ContextMenuGroupProps) { return <Primitive.Group data-slot="context-menu-group" {...props} />; } type ContextMenuSubProps = React.ComponentProps<typeof Primitive.Sub>; function ContextMenuSub(props: ContextMenuSubProps) { return <Primitive.Sub data-slot="context-menu-sub" {...props} />; } type ContextMenuRadioGroupProps = React.ComponentProps< typeof Primitive.RadioGroup >; function ContextMenuRadioGroup(props: ContextMenuRadioGroupProps) { return ( <Primitive.RadioGroup data-slot="context-menu-radio-group" {...props} /> ); } type ContextMenuContentProps = React.ComponentProps<typeof Primitive.Content>; function ContextMenuContent({ className, collisionPadding = 12, ...props }: ContextMenuContentProps) { return ( <Primitive.Portal> <Primitive.Content data-slot="context-menu-content" collisionPadding={collisionPadding} className={cn( surface, "max-h-(--radix-context-menu-content-available-height) origin-(--radix-context-menu-content-transform-origin) overflow-y-auto", className, )} {...props} /> </Primitive.Portal> ); } type ContextMenuItemProps = React.ComponentProps<typeof Primitive.Item> & { /** Indent the item so it lines up with items that show a check or icon. */ inset?: boolean; /** Style the item as a destructive action (delete, sign out). */ destructive?: boolean; }; function ContextMenuItem({ className, inset, destructive, ...props }: ContextMenuItemProps) { return ( <Primitive.Item data-slot="context-menu-item" data-inset={inset ? "" : undefined} data-variant={destructive ? "destructive" : "default"} className={cn( itemBase, "data-[inset]:ps-8", "data-[variant=destructive]:text-destructive data-[variant=destructive]:data-[highlighted]:bg-destructive/10 data-[variant=destructive]:data-[highlighted]:text-destructive data-[variant=destructive]:[&_svg]:!text-destructive", className, )} {...props} /> ); } type ContextMenuCheckboxItemProps = React.ComponentProps< typeof Primitive.CheckboxItem >; function ContextMenuCheckboxItem({ className, children, ...props }: ContextMenuCheckboxItemProps) { return ( <Primitive.CheckboxItem data-slot="context-menu-checkbox-item" className={cn(itemBase, "ps-8", className)} {...props} > <span className="pointer-events-none absolute start-2 flex size-4 items-center justify-center"> <Primitive.ItemIndicator> <Check aria-hidden="true" className="size-4 !text-foreground" /> </Primitive.ItemIndicator> </span> {children} </Primitive.CheckboxItem> ); } type ContextMenuRadioItemProps = React.ComponentProps< typeof Primitive.RadioItem >; function ContextMenuRadioItem({ className, children, ...props }: ContextMenuRadioItemProps) { return ( <Primitive.RadioItem data-slot="context-menu-radio-item" className={cn(itemBase, "ps-8", className)} {...props} > <span className="pointer-events-none absolute start-2 flex size-4 items-center justify-center"> <Primitive.ItemIndicator> <Circle aria-hidden="true" className="size-2 fill-current !text-foreground" /> </Primitive.ItemIndicator> </span> {children} </Primitive.RadioItem> ); } type ContextMenuLabelProps = React.ComponentProps<typeof Primitive.Label> & { /** Indent the label to match inset items. */ inset?: boolean; }; function ContextMenuLabel({ className, inset, ...props }: ContextMenuLabelProps) { return ( <Primitive.Label data-slot="context-menu-label" data-inset={inset ? "" : undefined} className={cn( "px-2 py-1.5 text-xs font-medium text-muted-foreground data-[inset]:ps-8", className, )} {...props} /> ); } type ContextMenuSeparatorProps = React.ComponentProps< typeof Primitive.Separator >; function ContextMenuSeparator({ className, ...props }: ContextMenuSeparatorProps) { return ( <Primitive.Separator data-slot="context-menu-separator" className={cn("-mx-1 my-1 h-px bg-border", className)} {...props} /> ); } type ContextMenuShortcutProps = React.ComponentProps<"span">; /** Right-aligned keyboard hint. Decorative: the accessible name stays the item text, so add `aria-keyshortcuts` on the item when the shortcut is real. */ function ContextMenuShortcut({ className, ...props }: ContextMenuShortcutProps) { return ( <span data-slot="context-menu-shortcut" aria-hidden="true" className={cn( "ms-auto ps-4 font-mono text-xs tracking-wide text-muted-foreground", className, )} {...props} /> ); } type ContextMenuSubTriggerProps = React.ComponentProps< typeof Primitive.SubTrigger > & { /** Indent the trigger to match inset items. */ inset?: boolean; }; function ContextMenuSubTrigger({ className, inset, children, ...props }: ContextMenuSubTriggerProps) { return ( <Primitive.SubTrigger data-slot="context-menu-sub-trigger" data-inset={inset ? "" : undefined} className={cn( itemBase, "data-[inset]:ps-8 data-[state=open]:bg-accent data-[state=open]:text-accent-foreground", className, )} {...props} > {children} <ChevronRight aria-hidden="true" className="ms-auto size-4 rtl:rotate-180" /> </Primitive.SubTrigger> ); } type ContextMenuSubContentProps = React.ComponentProps< typeof Primitive.SubContent >; function ContextMenuSubContent({ className, collisionPadding = 12, ...props }: ContextMenuSubContentProps) { return ( <Primitive.Portal> <Primitive.SubContent data-slot="context-menu-sub-content" collisionPadding={collisionPadding} className={cn( surface, "origin-(--radix-context-menu-content-transform-origin)", className, )} {...props} /> </Primitive.Portal> ); } export { ContextMenu, ContextMenuTrigger, ContextMenuContent, ContextMenuGroup, ContextMenuItem, ContextMenuCheckboxItem, ContextMenuRadioGroup, ContextMenuRadioItem, ContextMenuLabel, ContextMenuSeparator, ContextMenuShortcut, ContextMenuSub, ContextMenuSubTrigger, ContextMenuSubContent, type ContextMenuProps, type ContextMenuTriggerProps, type ContextMenuContentProps, type ContextMenuGroupProps, type ContextMenuItemProps, type ContextMenuCheckboxItemProps, type ContextMenuRadioGroupProps, type ContextMenuRadioItemProps, type ContextMenuLabelProps, type ContextMenuSeparatorProps, type ContextMenuShortcutProps, type ContextMenuSubProps, type ContextMenuSubTriggerProps, type ContextMenuSubContentProps, };Update the import paths to match your project setup.
$ pnpm dlx shadcn@latest add https://ui.ballmac.com/r/base/context-menu.jsonInstall the dependencies.
$ pnpm add lucide-react @base-ui/react@^1.9.0Add the Ballmac items it builds on (their Base UI versions where they have one).
$ pnpm dlx shadcn@latest add https://ui.ballmac.com/r/base/direction.json https://ui.ballmac.com/r/base/positioner.jsonCopy the source into your project.
components/ballmac/context-menu.tsx// Ballmac UI: Context Menu. https://ui.ballmac.com/components/context-menu // Based on shadcn/ui Context Menu (MIT, Copyright (c) 2023 shadcn), restyled with tokens, destructive and inset items, and a shortcut slot. "use client"; import * as React from "react"; import { Check, ChevronRight, Circle } from "lucide-react"; import { ContextMenu as Primitive } from "@base-ui/react/context-menu"; import { DirectionProvider, useDirection } from "@/lib/ballmac/direction"; import { selectHandler, splitPositioner } from "@/lib/ballmac/positioner"; import { cn } from "@/lib/utils"; const itemBase = "relative flex min-h-[var(--bm-menu-item-h,2rem)] cursor-default select-none items-center gap-2 rounded-[var(--bm-menu-item-radius,var(--radius-md))] px-2 py-1.5 text-sm outline-none transition-colors data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[highlighted]:bg-accent data-[highlighted]:text-accent-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground"; const surface = "min-w-[12rem] origin-(--transform-origin) overflow-hidden rounded-xl border bg-popover/[var(--bm-material-alpha,100%)] backdrop-blur-[var(--bm-material-blur,0px)] p-[var(--bm-menu-pad,0.25rem)] text-popover-foreground shadow-[var(--bm-shadow-popover,0_12px_36px_-10px_rgb(0_0_0/0.25))] transition-[opacity,scale] duration-150 data-starting-style:scale-95 data-starting-style:opacity-0 data-ending-style:scale-95 data-ending-style:opacity-0 motion-reduce:transition-none"; type ContextMenuProps = React.ComponentProps<typeof Primitive.Root> & { /** Reading direction for the arrow keys. Defaults to the page's. */ dir?: "ltr" | "rtl"; }; function ContextMenu({ dir: dirProp, ...props }: ContextMenuProps) { const dir = useDirection(dirProp); return ( <DirectionProvider dir={dir}> <Primitive.Root {...props} /> </DirectionProvider> ); } type ContextMenuTriggerProps = Omit<React.ComponentProps<typeof Primitive.Trigger>, "className"> & { className?: string }; function ContextMenuTrigger(props: ContextMenuTriggerProps) { return <Primitive.Trigger data-slot="context-menu-trigger" {...props} />; } type ContextMenuGroupProps = React.ComponentProps<typeof Primitive.Group>; function ContextMenuGroup(props: ContextMenuGroupProps) { return <Primitive.Group data-slot="context-menu-group" {...props} />; } type ContextMenuSubProps = React.ComponentProps<typeof Primitive.SubmenuRoot>; function ContextMenuSub(props: ContextMenuSubProps) { return <Primitive.SubmenuRoot {...props} />; } type ContextMenuRadioGroupProps = Omit<React.ComponentProps<typeof Primitive.RadioGroup>, "onValueChange"> & { onValueChange?: (value: string) => void; }; function ContextMenuRadioGroup({ onValueChange, ...props }: ContextMenuRadioGroupProps) { return ( <Primitive.RadioGroup data-slot="context-menu-radio-group" onValueChange={(v) => onValueChange?.(String(v))} {...props} /> ); } type PositionProps = Pick<React.ComponentProps<typeof Primitive.Positioner>, "side" | "align" | "alignOffset" | "collisionPadding">; type ContextMenuContentProps = Omit<React.ComponentProps<typeof Primitive.Popup>, "className"> & PositionProps & { className?: string; }; function ContextMenuContent({ className, collisionPadding = 12, ...rest }: ContextMenuContentProps) { const [position, props] = splitPositioner(rest); return ( <Primitive.Portal> <Primitive.Positioner collisionPadding={collisionPadding} className="z-50 outline-none" {...position}> <Primitive.Popup data-slot="context-menu-content" className={cn( surface, "max-h-(--available-height) overflow-y-auto outline-none", className, )} {...props} /> </Primitive.Positioner> </Primitive.Portal> ); } type ContextMenuItemProps = Omit<React.ComponentProps<typeof Primitive.Item>, "className"> & { className?: string; /** Called when the item is chosen, with the pointer or the keyboard. */ onSelect?: (event: Event) => void; /** Indent the item so it lines up with items that show a check or icon. */ inset?: boolean; /** Style the item as a destructive action (delete, sign out). */ destructive?: boolean; }; function ContextMenuItem({ className, inset, destructive, onSelect, onClick, ...props }: ContextMenuItemProps) { return ( <Primitive.Item data-slot="context-menu-item" data-inset={inset ? "" : undefined} data-variant={destructive ? "destructive" : "default"} onClick={selectHandler(onSelect, onClick as never) as never} className={cn( itemBase, "data-[inset]:ps-8", "data-[variant=destructive]:text-destructive data-[variant=destructive]:data-[highlighted]:bg-destructive/10 data-[variant=destructive]:data-[highlighted]:text-destructive data-[variant=destructive]:[&_svg]:!text-destructive", className, )} {...props} /> ); } type ContextMenuCheckboxItemProps = Omit<React.ComponentProps<typeof Primitive.CheckboxItem>, "className" | "onClick"> & { className?: string; onSelect?: (event: Event) => void; }; function ContextMenuCheckboxItem({ className, children, onSelect, ...props }: ContextMenuCheckboxItemProps) { return ( <Primitive.CheckboxItem data-slot="context-menu-checkbox-item" onClick={selectHandler(onSelect) as never} className={cn(itemBase, "ps-8", className)} {...props} > <span className="pointer-events-none absolute start-2 flex size-4 items-center justify-center"> <Primitive.CheckboxItemIndicator> <Check aria-hidden="true" className="size-4 !text-foreground" /> </Primitive.CheckboxItemIndicator> </span> {children} </Primitive.CheckboxItem> ); } type ContextMenuRadioItemProps = Omit<React.ComponentProps<typeof Primitive.RadioItem>, "className" | "onClick"> & { className?: string; onSelect?: (event: Event) => void; }; function ContextMenuRadioItem({ className, children, onSelect, ...props }: ContextMenuRadioItemProps) { return ( <Primitive.RadioItem data-slot="context-menu-radio-item" onClick={selectHandler(onSelect) as never} className={cn(itemBase, "ps-8", className)} {...props} > <span className="pointer-events-none absolute start-2 flex size-4 items-center justify-center"> <Primitive.RadioItemIndicator> <Circle aria-hidden="true" className="size-2 fill-current !text-foreground" /> </Primitive.RadioItemIndicator> </span> {children} </Primitive.RadioItem> ); } type ContextMenuLabelProps = React.ComponentProps<"div"> & { /** Indent the label to match inset items. */ inset?: boolean; }; /** A heading inside the menu. A plain element: Base UI's group label needs a group around it, and this one can sit anywhere. */ function ContextMenuLabel({ className, inset, ...props }: ContextMenuLabelProps) { return ( <div data-slot="context-menu-label" data-inset={inset ? "" : undefined} className={cn( "px-2 py-1.5 text-xs font-medium text-muted-foreground data-[inset]:ps-8", className, )} {...props} /> ); } type ContextMenuSeparatorProps = Omit<React.ComponentProps<typeof Primitive.Separator>, "className"> & { className?: string }; function ContextMenuSeparator({ className, ...props }: ContextMenuSeparatorProps) { return ( <Primitive.Separator data-slot="context-menu-separator" className={cn("-mx-1 my-1 h-px bg-border", className)} {...props} /> ); } type ContextMenuShortcutProps = React.ComponentProps<"span">; /** Right-aligned keyboard hint. Decorative: the accessible name stays the item text, so add `aria-keyshortcuts` on the item when the shortcut is real. */ function ContextMenuShortcut({ className, ...props }: ContextMenuShortcutProps) { return ( <span data-slot="context-menu-shortcut" aria-hidden="true" className={cn( "ms-auto ps-4 font-mono text-xs tracking-wide text-muted-foreground", className, )} {...props} /> ); } type ContextMenuSubTriggerProps = Omit<React.ComponentProps<typeof Primitive.SubmenuTrigger>, "className"> & { className?: string; /** Indent the trigger to match inset items. */ inset?: boolean; }; function ContextMenuSubTrigger({ className, inset, children, ...props }: ContextMenuSubTriggerProps) { return ( <Primitive.SubmenuTrigger data-slot="context-menu-sub-trigger" data-inset={inset ? "" : undefined} className={cn( itemBase, "data-[inset]:ps-8 data-popup-open:bg-accent data-popup-open:text-accent-foreground", className, )} {...props} > {children} <ChevronRight aria-hidden="true" className="ms-auto size-4 rtl:rotate-180" /> </Primitive.SubmenuTrigger> ); } type ContextMenuSubContentProps = Omit<React.ComponentProps<typeof Primitive.Popup>, "className"> & PositionProps & { className?: string; }; function ContextMenuSubContent({ className, collisionPadding = 12, ...rest }: ContextMenuSubContentProps) { const [position, props] = splitPositioner(rest); return ( <Primitive.Portal> <Primitive.Positioner collisionPadding={collisionPadding} className="z-50 outline-none" {...position}> <Primitive.Popup data-slot="context-menu-sub-content" className={cn(surface, "outline-none", className)} {...props} /> </Primitive.Positioner> </Primitive.Portal> ); } export { ContextMenu, ContextMenuTrigger, ContextMenuContent, ContextMenuGroup, ContextMenuItem, ContextMenuCheckboxItem, ContextMenuRadioGroup, ContextMenuRadioItem, ContextMenuLabel, ContextMenuSeparator, ContextMenuShortcut, ContextMenuSub, ContextMenuSubTrigger, ContextMenuSubContent, type ContextMenuProps, type ContextMenuTriggerProps, type ContextMenuContentProps, type ContextMenuGroupProps, type ContextMenuItemProps, type ContextMenuCheckboxItemProps, type ContextMenuRadioGroupProps, type ContextMenuRadioItemProps, type ContextMenuLabelProps, type ContextMenuSeparatorProps, type ContextMenuShortcutProps, type ContextMenuSubProps, type ContextMenuSubTriggerProps, type ContextMenuSubContentProps, };Update the import paths to match your project setup.
Usage
import { ContextMenu, ContextMenuTrigger, ContextMenuContent, ContextMenuGroup, ContextMenuItem, ContextMenuCheckboxItem, ContextMenuRadioGroup, ContextMenuRadioItem, ContextMenuLabel, ContextMenuSeparator, ContextMenuShortcut, ContextMenuSub, ContextMenuSubTrigger, ContextMenuSubContent } from "@/components/ballmac/context-menu"The full example is in the Code tab above.
Examples
View options
"use client";
import * as React from "react";
import {
ContextMenu,
ContextMenuCheckboxItem,
ContextMenuContent,
ContextMenuLabel,
ContextMenuRadioGroup,
ContextMenuRadioItem,
ContextMenuSeparator,
ContextMenuTrigger,
} from "@/components/ballmac/context-menu";
export default function ContextMenuStates() {
const [grid, setGrid] = React.useState(true);
const [zoom, setZoom] = React.useState("fit");
return (
<ContextMenu>
<ContextMenuTrigger
tabIndex={0}
aria-label="Canvas. Right-click or press Shift+F10 for view options"
className="grid h-40 w-full max-w-sm place-items-center rounded-xl border border-dashed bg-muted/40 text-sm text-muted-foreground outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50"
>
{grid ? "Grid on" : "Grid off"} · zoom {zoom}
</ContextMenuTrigger>
<ContextMenuContent className="w-52">
<ContextMenuLabel>View</ContextMenuLabel>
<ContextMenuCheckboxItem checked={grid} onCheckedChange={setGrid}>
Show grid
</ContextMenuCheckboxItem>
<ContextMenuSeparator />
<ContextMenuRadioGroup value={zoom} onValueChange={setZoom}>
<ContextMenuRadioItem value="fit">Fit to screen</ContextMenuRadioItem>
<ContextMenuRadioItem value="100%">Actual size</ContextMenuRadioItem>
<ContextMenuRadioItem value="200%" disabled>
200% (unavailable)
</ContextMenuRadioItem>
</ContextMenuRadioGroup>
</ContextMenuContent>
</ContextMenu>
);
}API reference
<ContextMenuItem>
| Prop | Type | Default |
|---|---|---|
insetIndent the item so it lines up with items that show a check or icon. | boolean | — |
destructiveStyle the item as a destructive action (delete, sign out). | boolean | — |
<ContextMenuLabel>
| Prop | Type | Default |
|---|---|---|
insetIndent the label to match inset items. | boolean | — |
<ContextMenuSubTrigger>
| Prop | Type | Default |
|---|---|---|
insetIndent the trigger to match inset items. | boolean | — |
Also accepts the standard attributes of its root element.
Accessibility
| Key | Action |
|---|---|
| Right-click / long-press | Opens the menu at the pointer |
| Shift+F10 / Menu key | Opens it from a focused trigger |
| ArrowUp / ArrowDown | Moves between items |
| ArrowRight / ArrowLeft | Opens and closes a submenu |
| Escape | Closes the menu |
Quality scorecard
Every applicable check passes
Measured in Chromium 153.0.8010.12 on October 19, 2026, on version 1.0.1, across 2 examples.
Passed: Accessibility scan
No serious or critical issues in light and dark, on a phone and a desktop (axe-core 4.13.0, WCAG 2.1 AA and best-practice rules).
Passed: Small screens
No sideways scrolling at 360, 390 or 1280 px wide.
Passed: Reduced motion
No endless animation to begin with.
Passed: Right to left
Mirrors correctly in Arabic, Hebrew, Persian and Urdu layouts (0% of elements off the mirror, limit 15%).
Passed: Clean console
No console errors or React hydration errors while loading.
Passed: Keyboard
2 tab stops, each showing a visible change when it takes focus. 5 documented keys.
Not applicable: Loading, empty and error
Does not show data or take submissions.
Passed: Automated tests
Covered by context-menu.test.tsx.
For information: Footprint
2.1 KB of source (gzip) in 1 file. Installs radix-ui, lucide-react.
Automated checks find a subset of problems and do not replace testing with a screen reader and a keyboard in your own app. What they miss.
Use with AI
Shows actions at the pointer on right-click or long-press. Keyboard users open it with Shift+F10 or the Menu key on a focusable trigger. With the shadcn MCP server set up (guide), ask your agent:
Add the Ballmac UI Context Menu (@ballmac/context-menu) to this project with the shadcn MCP, then use it where it fits.
Use it for
- File, card and canvas actions
- Secondary actions that also exist elsewhere
- Desktop-style apps
Not for
- The only way to reach an action; menus must be discoverable, so also offer a dropdown-menu button
- Touch-first layouts without a visible trigger
Registry JSON: https://ui.ballmac.com/r/context-menu.json
Credits
Based on shadcn/ui Context Menu, adapted by Ballmac. Free to use in personal and commercial projects.
- Registry
- @ballmac/directionshadcn/utils
Pairs well with
Dropdown Menu
An action menu on a trigger with checkbox and radio items, submenus, shortcut hints and destructive rows, built on Radix for full keyboard and typeahead support.
Card
A composable content surface with compact spacing, an action slot, and optional interactive feedback.
Accordion
Vertically stacked disclosure sections on Radix Accordion, single or multiple open, with hairline dividers, a rotating plus and height animation.
Avatar
A Radix avatar with image and initials fallback, three sizes, an optional presence dot, and AvatarGroup for overlapping stacks with a +N overflow counter.
Ballmac UI Pro
Need the whole screen, not one piece?
311 premium blocks (dashboards, settings, calendars, mail, shops, onboarding), a private shadcn registry and Figma tokens. Blocks that show data come with loading, empty and error states built in.
Not ready? Try three Pro blocks free
Leave your email and the blocks appear right here, ready to copy. Yours to use in any project.