--- title: Context Menu description: Displays a menu of actions triggered by a right click. base: aria component: true links: doc: https://react-aria.adobe.com/Menu api: https://react-aria.adobe.com/Menu#api --- ## Installation Command Manual ```bash npx shadcn@latest add context-menu ``` Install the following dependencies: ```bash npm install react-aria-components ``` Copy and paste the following code into your project. Update the import paths to match your project setup. ## Usage ```tsx showLineNumbers import { Pressable } from "react-aria-components" import { ContextMenu, ContextMenuItem, ContextMenuTrigger, } from "@/components/ui/context-menu" ``` ```tsx showLineNumbers
Right click here
Profile Billing Team Subscription
``` ## Composition Use the following composition to build a `ContextMenu`: ```text ContextMenuTrigger ├── Pressable └── ContextMenuContent ├── ContextMenuGroup │ ├── ContextMenuLabel │ ├── ContextMenuItem │ └── ContextMenuItem ├── ContextMenuSeparator ├── ContextMenuGroup │ ├── ContextMenuLabel │ ├── ContextMenuItem │ └── ContextMenuItem └── ContextMenuSub ├── ContextMenuSubTrigger └── ContextMenuSubContent └── ContextMenuGroup ├── ContextMenuItem └── ContextMenuItem ``` ## Basic A simple context menu with a few actions. ## Submenu Use `ContextMenuSub` to nest secondary actions. ## Shortcuts Add `ContextMenuShortcut` to show keyboard hints. ## Groups Group related actions and separate them with dividers. ## Icons Combine icons with labels for quick scanning. ## Checkboxes Use `selectionMode="multiple"` for toggles. ## Radio Use `selectionMode="single"` for exclusive choices. ## Destructive Use `variant="destructive"` to style the menu item as destructive. ## Placement Control submenu placement with the `placement` prop. ## RTL To enable RTL support in shadcn/ui, see the [RTL configuration guide](/docs/rtl). Use `placement="end"` to place the menu on the logical end side of the trigger. ```tsx showLineNumbers
Right click here
Profile Billing Team Subscription
``` ## API Reference See the [React Aria](https://react-aria.adobe.com/Menu#api) documentation for more information.