mirror of
https://github.com/shadcn-ui/ui.git
synced 2026-06-26 06:05:56 +00:00
67 lines
1.5 KiB
Plaintext
67 lines
1.5 KiB
Plaintext
---
|
|
title: Context Menu
|
|
description: Displays a menu to the user — such as a set of actions or functions — triggered by a button.
|
|
component: true
|
|
radix:
|
|
link: https://www.radix-ui.com/docs/primitives/components/context-menu
|
|
api: https://www.radix-ui.com/docs/primitives/components/context-menu#api-reference
|
|
---
|
|
|
|
<ComponentExample src="/components/examples/context-menu/demo.tsx">
|
|
<ContextMenuDemo />
|
|
</ComponentExample>
|
|
|
|
## Installation
|
|
|
|
```bash
|
|
npx shadcn-ui add context-menu
|
|
```
|
|
|
|
<Accordion type="single" collapsible>
|
|
<AccordionItem value="manual-installation">
|
|
<AccordionTrigger>Manual Installation</AccordionTrigger>
|
|
<AccordionContent>
|
|
|
|
1. Install the `@radix-ui/react-context-menu` component from radix-ui:
|
|
|
|
```bash
|
|
npm install @radix-ui/react-context-menu
|
|
```
|
|
|
|
2. Copy and paste the following code into your project.
|
|
|
|
<ComponentSource src="/components/ui/context-menu.tsx" />
|
|
|
|
<Callout>
|
|
This is the `<ContextMenu />` primitive. You can place it in a file at
|
|
`components/ui/context-menu.tsx`.
|
|
</Callout>
|
|
|
|
</AccordionContent>
|
|
|
|
</AccordionItem>
|
|
</Accordion>
|
|
|
|
## Usage
|
|
|
|
```tsx
|
|
import {
|
|
ContextMenu,
|
|
ContextMenuContent,
|
|
ContextMenuItem,
|
|
ContextMenuTrigger,
|
|
} from "@/components/ui/context-menu"
|
|
```
|
|
|
|
```tsx
|
|
<ContextMenu>
|
|
<ContextMenuTrigger>Right click</ContextMenuTrigger>
|
|
<ContextMenuContent>
|
|
<ContextMenuItem>Profile</ContextMenuItem>
|
|
<ContextMenuItem>Billing</ContextMenuItem>
|
|
<ContextMenuItem>Team</ContextMenuItem>
|
|
<ContextMenuItem>Subscription</ContextMenuItem>
|
|
</ContextMenuContent>
|
|
</ContextMenu>
|
|
```
|