Context Menu

Context Menu

Overlay
Navigation

Right-click context menu with keyboard navigation and custom actions.

Preview

Right-click a file row, or focus it and press Shift+F10, to open the context menu. The open state is shown next to the list.

Q4 roadmap.pdf
PDF, 2.4 MB
Brand guidelines.pdf
PDF, 8.1 MB
Release notes.md
Markdown, 12 KB

With Section Labels

Organize menu items with section headers

Project Document

Right-click to see organized menu with labels

Props

Component API reference

ContextMenuItem

PropTypeDefaultDescription
iconLucideIcon—Icon component to display
shortcutstring—Keyboard shortcut text
destructivebooleanfalseDestructive action styling
disabledbooleanfalseDisable the menu item
onSelect() => void—Click handler

ContextMenuLabel

PropTypeDefaultDescription
children*ReactNode—Label text content

Usage

Import and implementation examples

import {
ContextMenu,
ContextMenuTrigger,
ContextMenuContent,
ContextMenuItem,
ContextMenuSeparator,
ContextMenuLabel,
} from '@/components/ui/context-menu'
import { Copy, Edit, Trash2 } from 'lucide-react'
<ContextMenu>
<ContextMenuTrigger>
<div>Right-click me!</div>
</ContextMenuTrigger>
<ContextMenuContent>
<ContextMenuItem icon={Copy} shortcut="⌘C">
Copy
</ContextMenuItem>
<ContextMenuItem icon={Edit} shortcut="⌘E">
Edit
</ContextMenuItem>
<ContextMenuSeparator />
<ContextMenuLabel>Danger Zone</ContextMenuLabel>
<ContextMenuItem icon={Trash2} destructive>
Delete
</ContextMenuItem>
</ContextMenuContent>
</ContextMenu>

Features

Built-in functionality

  • Right-click trigger: Opens at the pointer, or at the trigger from the keyboard
  • Keyboard shortcuts: Display shortcut hints
  • Section labels: Group related items with headers
  • Destructive styling: Red color for dangerous actions
  • Icon support: Add icons to menu items
  • Separators: Visual dividers between sections
  • Click outside: Closes when clicking outside

Accessibility

Accessibility considerations

ARIA Attributes

Built on Radix Context Menurole="menu" for menu containerrole="menuitem" for itemsaria-disabled for disabled items

Keyboard Navigation

KeyAction
Shift+F10 / Menu keyOpen the menu from the focused trigger
Arrow Up/DownNavigate items
Home/EndFirst or last item
Letter keysJump to the item that starts with the letter
Enter/SpaceActivate item
EscapeClose menu

Notes

  • The trigger is focusable, so the menu works without a mouse
  • Focus moves into the menu on open and back to the trigger on close
  • Click outside closes the menu
  • Long press opens the menu on touch screens