Files
Jonathan Summers-MuirandJordi Enric 637167a27b Feat/non centered dialog option (#29776)
* init

* Update dialog.tsx

* add example

* update docs

* Update packages/ui/src/components/shadcn/ui/dialog.tsx

Co-authored-by: Jonathan Summers-Muir <MildTomato@users.noreply.github.com>

---------

Co-authored-by: Jordi Enric <37541088+jordienr@users.noreply.github.com>
2024-11-05 13:03:11 +08:00

100 lines
2.5 KiB
Plaintext

---
title: Dialog
description: A window overlaid on either the primary window or another dialog window, rendering the content underneath inert.
featured: true
component: true
links:
doc: https://www.radix-ui.com/docs/primitives/components/dialog
api: https://www.radix-ui.com/docs/primitives/components/dialog#api-reference
source:
radix: true
shadcn: true
---
<ComponentPreview name="dialog-demo" peekCode wide />
## Usage
```tsx
import {
Dialog,
DialogContent,
DialogDescription,
DialogHeader,
DialogTitle,
DialogTrigger,
} from '@/components/ui/dialog'
```
```tsx
<Dialog>
<DialogTrigger>Open</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>Are you 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>
```
## Examples
### Custom close button
<ComponentPreview name="dialog-close-button" />
### Centered behaviour
You can control whether the dialog is centered by passing `centered={false}` to the `DialogContent` component.
```tsx {3}
<Dialog>
<ContextMenuTrigger>Click here</ContextMenuTrigger>
<DialogContent centered={false}>
{/*
* Content in here
*/}
</DialogContent>
</Dialog>
```
<ComponentPreview name="dialog-centered-off" />
## 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 {14-25}
<Dialog>
<ContextMenu>
<ContextMenuTrigger>Dialog not centered</ContextMenuTrigger>
<ContextMenuContent>
<ContextMenuItem>Open</ContextMenuItem>
<ContextMenuItem>Download</ContextMenuItem>
<DialogTrigger asChild>
<ContextMenuItem>
<span>Delete</span>
</ContextMenuItem>
</DialogTrigger>
</ContextMenuContent>
</ContextMenu>
<DialogContent>
<DialogHeader>
<DialogTitle>Are you 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>
```