GooseUI

Components

Context Menu

New

Context Menu opens a list of actions where the user right-clicks, long-presses on a touch screen, or presses Shift+F10 or the Menu key. It lives in the browser top layer as a popover, sits at the pointer and flips away from the viewport edges. Items look and behave like the ones in Dropdown Menu, plus checkbox and radio items, labels, shortcuts and nested submenus.

Browser Support

Limited availability
4 features
Details
Popover

Shows the menu in the top layer with light dismiss. Submenus are nested popovers, so the parent stays open.

Your browser:
Anchor positioning

Places the menu at the pointer and flips it near the edges. Without it, JavaScript measures the menu and clamps it into the viewport.

Your browser:
@starting-style

Fades and scales the menu in. Without it the menu appears instantly.

Your browser:
transition-behavior

Keeps the closing animation running while the popover leaves the top layer.

Your browser:

Preview

Right-click a file, long-press it on a touch screen, or focus it with Tab and press Shift+F10.

  • Q3 revenue forecast.xlsx

    248 KB · edited 2 h ago

  • Onboarding checklist.docx

    36 KB · edited yesterday

  • Offsite Lisbon 2026

    142 photos

  • Homepage hero v4.png

    1.8 MB · edited Nov 12

Installation

npx shadcn@latest add @gooseui/context-menu
pnpm dlx shadcn@latest add @gooseui/context-menu
yarn dlx shadcn@latest add @gooseui/context-menu
bunx --bun shadcn@latest add @gooseui/context-menu

Usage

import {
  ContextMenu,
  ContextMenuContent,
  ContextMenuItem,
  ContextMenuSeparator,
  ContextMenuTrigger,
} from "@/components/ui/context-menu"

export function FileCard() {
  return (
    <ContextMenu>
      <ContextMenuTrigger aria-label="report.pdf. Shift+F10 for actions" className="rounded-lg border p-4">
        report.pdf
      </ContextMenuTrigger>
      <ContextMenuContent>
        <ContextMenuItem shortcut="⌘O" onSelect={() => open()}>Open</ContextMenuItem>
        <ContextMenuItem shortcut="⌘D" onSelect={() => duplicate()}>Duplicate</ContextMenuItem>
        <ContextMenuSeparator />
        <ContextMenuItem variant="destructive" onSelect={() => remove()}>Delete</ContextMenuItem>
      </ContextMenuContent>
    </ContextMenu>
  )
}

Examples

Checkbox and radio items

View options of a canvas: checkbox items toggle the grid and rulers, a radio group picks the zoom. Labels and inset keep the text aligned.

Header
Search
Product grid

100% · show grid on

Type a letter to jump to an item: s cycles through Show grid and Snap to grid.

const [grid, setGrid] = useState(true)
const [zoom, setZoom] = useState("100")

<ContextMenu>
  <ContextMenuTrigger aria-label="Canvas. Shift+F10 for view options">…</ContextMenuTrigger>
  <ContextMenuContent>
    <ContextMenuLabel inset>View</ContextMenuLabel>
    <ContextMenuCheckboxItem checked={grid} onCheckedChange={setGrid} shortcut="⌘'">
      Show grid
    </ContextMenuCheckboxItem>
    <ContextMenuSeparator />
    <ContextMenuLabel inset id="zoom-label">Zoom</ContextMenuLabel>
    <ContextMenuRadioGroup value={zoom} onValueChange={setZoom} aria-labelledby="zoom-label">
      <ContextMenuRadioItem value="50">50%</ContextMenuRadioItem>
      <ContextMenuRadioItem value="100">100%</ContextMenuRadioItem>
      <ContextMenuRadioItem value="200">200%</ContextMenuRadioItem>
    </ContextMenuRadioGroup>
  </ContextMenuContent>
</ContextMenu>

Submenu

ContextMenuSub nests another level. It opens on hover, click, Enter or Arrow Right and closes with Arrow Left or Escape.

<ContextMenuSub>
  <ContextMenuSubTrigger>
    <UsersIcon />
    Share
  </ContextMenuSubTrigger>
  <ContextMenuSubContent>
    <ContextMenuItem onSelect={copyLink}>Copy link</ContextMenuItem>
    <ContextMenuItem onSelect={sendEmail}>Send by email</ContextMenuItem>
  </ContextMenuSubContent>
</ContextMenuSub>

Keep the menu open

Call event.preventDefault() in onSelect to keep the menu open, for example when several checkboxes are toggled in a row.

<ContextMenuCheckboxItem
  checked={rulers}
  onCheckedChange={setRulers}
  onSelect={(event) => event.preventDefault()}
>
  Rulers
</ContextMenuCheckboxItem>

Props

PropTypeDefaultDescription
onOpenChange(open: boolean) => void-ContextMenu: called when the menu opens or closes.
onSelect(event) => void-Items: runs on click, Enter or Space. event.preventDefault() keeps the menu open.
variant"default" | "destructive""default"ContextMenuItem: red style for destructive actions.
shortcutReactNode-Items: hint such as ⌘D shown at the end of the item.
insetbooleanfalseItem, label, sub trigger: indent to line up with checkbox items.
textValuestring-Items: text for typeahead when the children are not plain text.
disabledbooleanfalseContextMenuTrigger: let the browser show its own menu instead. Items: skip the item in keyboard navigation and clicks.
checkedboolean-ContextMenuCheckboxItem: controlled checked state.
defaultCheckedbooleanfalseContextMenuCheckboxItem: initial checked state.
onCheckedChange(checked: boolean) => void-ContextMenuCheckboxItem: called with the new state.
valuestring-ContextMenuRadioGroup: controlled selected value.
defaultValuestring-ContextMenuRadioGroup: initial selected value.
onValueChange(value: string) => void-ContextMenuRadioGroup: called with the new value.
RadioItem valuestring-ContextMenuRadioItem: value of this option.

Components

ComponentDescription
ContextMenuRoot. Holds the open state and the pointer position.
ContextMenuTriggerArea that reacts to right-click, long-press, Shift+F10 and the Menu key. A focusable div.
ContextMenuContentThe menu itself, a popover with role=menu.
ContextMenuItemAction. Supports icons, shortcut and variant.
ContextMenuCheckboxItemItem with role=menuitemcheckbox.
ContextMenuRadioGroupGroup of radio items with one value.
ContextMenuRadioItemItem with role=menuitemradio.
ContextMenuLabelSmall caption for a group of items.
ContextMenuSeparatorThin line between groups.
ContextMenuShortcutKeyboard hint at the end of an item.
ContextMenuSubWraps one nested level.
ContextMenuSubTriggerItem that opens the submenu.
ContextMenuSubContentThe nested menu.

Features

  • Three ways to open — right-click, a 500 ms long-press on touch, Shift+F10 or the Menu key on a focused trigger
  • Keyboard — arrows, Home and End move between items, a letter jumps to the matching item, Escape and Tab close the menu and return focus
  • One highlight — the pointer moves focus, so the mouse and the keyboard never highlight two items at once
  • Edges — the menu flips to the other side of the pointer when there is no room; submenus flip to the left
  • Nested triggers — only the innermost trigger handles the gesture
  • Reduced motion — the open animation is turned off