mirror of
https://github.com/shadcn-ui/ui.git
synced 2026-07-07 22:18:39 +00:00
94 lines
2.3 KiB
Plaintext
94 lines
2.3 KiB
Plaintext
---
|
|
title: Dialog
|
|
description: A modal dialog that interrupts the user with important content and expects a response.
|
|
featured: true
|
|
component: true
|
|
radix:
|
|
link: https://www.radix-ui.com/docs/primitives/components/dialog
|
|
api: https://www.radix-ui.com/docs/primitives/components/dialog#api-reference
|
|
---
|
|
|
|
<ComponentExample src="/components/examples/dialog/demo.tsx">
|
|
<DialogDemo />
|
|
</ComponentExample>
|
|
|
|
## Installation
|
|
|
|
1. Install the `@radix-ui/react-dialog` component from radix-ui:
|
|
|
|
```bash
|
|
npm install @radix-ui/react-dialog
|
|
```
|
|
|
|
2. Copy and paste the following code into your project.
|
|
|
|
<ComponentSource src="/components/ui/dialog.tsx" />
|
|
|
|
<Callout>
|
|
|
|
This is the `<Dialog />` primitive. You can place it in a file at `components/ui/dialog.tsx`.
|
|
|
|
</Callout>
|
|
|
|
## Usage
|
|
|
|
```tsx
|
|
import {
|
|
Dialog,
|
|
DialogContent,
|
|
DialogDescription,
|
|
DialogHeader,
|
|
DialogTitle,
|
|
DialogTrigger,
|
|
} from "@/components/ui/dialog"
|
|
```
|
|
|
|
```tsx
|
|
<Dialog>
|
|
<DialogTrigger>Open</DialogTrigger>
|
|
<DialogContent>
|
|
<DialogHeader>
|
|
<DialogTitle>Are you sure absolutely sure?</DialogTitle>
|
|
<DialogDescription>
|
|
This action cannot be undone. This will permanently delete your account
|
|
and remove your data from our servers.
|
|
</DialogDescription>
|
|
</DialogHeader>
|
|
</DialogContent>
|
|
</Dialog>
|
|
```
|
|
|
|
## Notes
|
|
|
|
To activate the Dialog component from within a Context Menu or Dropdown Menu, you must encase the Context Menu or
|
|
Dropdown Menu component in the Dialog component. For more information, refer to the linked issue [here](https://github.com/radix-ui/primitives/issues/1836).
|
|
|
|
```tsx
|
|
<Dialog>
|
|
<ContextMenu>
|
|
<ContextMenuTrigger>Right click</ContextMenuTrigger>
|
|
<ContextMenuContent>
|
|
<ContextMenuItem>Open</ContextMenuItem>
|
|
<ContextMenuItem>Download</ContextMenuItem>
|
|
<DialogTrigger asChild>
|
|
<ContextMenuItem>
|
|
<span>Delete</span>
|
|
</ContextMenuItem>
|
|
</DialogTrigger>
|
|
</ContextMenuContent>
|
|
</ContextMenu>
|
|
<DialogContent>
|
|
<DialogHeader>
|
|
<DialogTitle>Are you sure absolutely sure?</DialogTitle>
|
|
<DialogDescription>
|
|
This action cannot be undone. Are you sure you want to permanently
|
|
delete this file from our servers?
|
|
</DialogDescription>
|
|
</DialogHeader>
|
|
<DialogFooter>
|
|
<Button type="submit">Confirm</Button>
|
|
</DialogFooter>
|
|
</DialogContent>
|
|
</Dialog>
|
|
```
|