Context Menu
Right-click menu with items, checkbox and radio items, submenus and shortcuts.
pnpm dlx @glinui/cli@latest add context-menuInstallation
pnpm dlx @glinui/cli@latest add context-menuPrefer the package?
Usage
Canvas
A menu for an empty canvas, with checkable view options.
"use client"
import { Globe, Plus } from "@phosphor-icons/react"import { ContextMenu, ContextMenuCheckboxItem, ContextMenuContent, ContextMenuItem, ContextMenuSeparator, ContextMenuShortcut, ContextMenuTrigger} from "@glinui/ui"
export function ContextCanvasExample() { return ( <div className="mx-auto w-full max-w-md"> <ContextMenu> <ContextMenuTrigger className="flex h-40 items-center justify-center rounded-2xl border border-dashed border-[var(--color-border)] bg-[var(--surface-1)] text-sm text-[var(--color-muted)]"> Right click the canvas </ContextMenuTrigger> <ContextMenuContent className="w-56"> <ContextMenuItem><Plus aria-hidden="true" className="size-4" />New frame <ContextMenuShortcut>F</ContextMenuShortcut></ContextMenuItem> <ContextMenuItem><Globe aria-hidden="true" className="size-4" />Paste here <ContextMenuShortcut>Ctrl V</ContextMenuShortcut></ContextMenuItem> <ContextMenuSeparator /> <ContextMenuCheckboxItem checked>Show grid</ContextMenuCheckboxItem> <ContextMenuCheckboxItem>Snap to objects</ContextMenuCheckboxItem> </ContextMenuContent> </ContextMenu> </div> )}Variants
Every look of the shared vocabulary: glinr (the default), plain (shadcn), solid, soft, outline, ghost, gradient and glass. Omit `variant` to follow the ambient design style.
import { ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuSeparator, ContextMenuTrigger } from "@glinui/ui"
const variants = ["glinr", "plain", "solid", "soft", "outline", "ghost", "gradient", "glass"] as const
export function Demo() { return ( <div className="grid grid-cols-2 gap-3 sm:grid-cols-4"> {variants.map((variant) => ( <ContextMenu key={variant} variant={variant}> <ContextMenuTrigger className="flex h-16 items-center justify-center rounded-lg border border-dashed text-xs"> Right click ({variant}) </ContextMenuTrigger> <ContextMenuContent> <ContextMenuItem>Copy</ContextMenuItem> <ContextMenuItem>Paste</ContextMenuItem> <ContextMenuSeparator /> <ContextMenuItem>Delete</ContextMenuItem> </ContextMenuContent> </ContextMenu> ))} </div> )}Glass (opt-in)
Glass is opt-in and needs a colourful or photographic backdrop. Pick one in the stage header.
import { ContextMenu, ContextMenuCheckboxItem, ContextMenuContent, ContextMenuItem, ContextMenuLabel, ContextMenuSeparator, ContextMenuShortcut, ContextMenuTrigger } from "@glinui/ui"
export function Demo() { return ( <ContextMenu variant="glass"> <ContextMenuTrigger className="flex h-32 w-72 items-center justify-center rounded-xl border border-dashed border-[var(--color-border)] text-sm text-[var(--color-muted)]"> Right click here </ContextMenuTrigger> <ContextMenuContent className="w-56"> <ContextMenuLabel>Actions</ContextMenuLabel> <ContextMenuItem>Back <ContextMenuShortcut>Cmd [</ContextMenuShortcut></ContextMenuItem> <ContextMenuItem>Reload <ContextMenuShortcut>Cmd R</ContextMenuShortcut></ContextMenuItem> <ContextMenuSeparator /> <ContextMenuCheckboxItem checked>Show bookmarks</ContextMenuCheckboxItem> </ContextMenuContent> </ContextMenu> )}Accessibility
- Opens on right click, long press on touch, or the keyboard context menu key.
- Focus moves into the menu and returns to the trigger on close.
- Check and radio items expose their checked state.
Keyboard Interactions
| Key | Action |
|---|---|
| Shift + F10 / Menu key | Open the menu from the focused trigger. |
| ArrowUp / ArrowDown | Move between items. |
| ArrowRight / ArrowLeft | Open or close a submenu. |
| Enter / Space | Select the focused item. |
| Escape | Close the menu. |
ARIA Attributes
- `role="menu"` and `menuitem`
- `aria-checked` on checkbox and radio items
- `aria-disabled` on disabled items
Reduced Motion
Panels fade and scale from 95% on open using transform and opacity only. With prefers-reduced-motion the animation is removed.
Affected properties
opacitytransformAPI Reference
ContextMenu
| Prop | Type | Required | Default | Description |
|---|---|---|---|---|
variant | ContextMenuVariant | No | ambient style (glinr) | Panel surface for content and submenus. Omit it for the ambient design style. `glass` is opt-in and needs a backdrop. |
onOpenChange | (open: boolean) => void | - | - | Called when the menu opens or closes. |
modal | boolean | - | true | Block outside interaction while open. |
ContextMenuItem and friends
| Prop | Type | Required | Default | Description |
|---|---|---|---|---|
inset | boolean | - | false | Item and label: add start padding to align with items that have indicators. |
disabled | boolean | - | false | Item: blocks selection and focus. |
onSelect | (event: Event) => void | - | - | Item: called on selection. |
variant | ContextMenuVariant | No | - | Surface look. Omit for the ambient design style (glinr by default). `glass` is opt-in and needs a rich backdrop. |
Source
Import directly from the package or browse the source on GitHub. Click any file to view it.
Import
import { ContextMenu } from "@glinui/ui"Source Files
Dependencies
@glinui/ui@phosphor-icons/react@radix-ui/react-context-menuclass-variance-authorityGenerated API Snapshot
Beta
Generated API Snapshot
BetaAuto-extracted from TypeScript source in packages/ui/src/components/context-menu.tsx. This section is in beta and may lag behind hand-curated docs. Regenerate with pnpm --filter @glinui/docs api:generate.
Generated: 2026-10-08T01:41:21.546Z · Full index: /docs/api-metadata
Primary Props Type
ContextMenuProps
ContextMenuContentProps
| Prop | Type | Required | Default | Description |
|---|---|---|---|---|
variant | ContextMenuVariant | No | - | Surface look. Omit for the ambient design style (glinr by default). `glass` is opt-in and needs a rich backdrop. |
ContextMenuProps
| Prop | Type | Required | Default | Description |
|---|---|---|---|---|
variant | ContextMenuVariant | No | - | Surface treatment shared by every floating panel in this menu. |