File size: 3,534 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
---
title: Dialog
description: Used to display a dialog prompt
links:
source: components/dialog
storybook: components-dialog--basic
recipe: dialog
ark: https://ark-ui.com/react/docs/components/dialog
---
<ExampleTabs name="dialog-basic" />
## Usage
```tsx
import { Dialog } from "@chakra-ui/react"
```
```tsx
<Dialog.Root>
<Dialog.Trigger />
<Dialog.Backdrop />
<Dialog.Positioner>
<Dialog.Content>
<Dialog.CloseTrigger />
<Dialog.Header>
<Dialog.Title />
</Dialog.Header>
<Dialog.Body />
<Dialog.Footer />
</Dialog.Content>
</Dialog.Positioner>
</Dialog.Root>
```
## Examples
### Sizes
Use the `size` prop to change the size of the dialog component.
<ExampleTabs name="dialog-with-sizes" />
### Cover
Use the `size="cover"` prop to make the dialog component cover the entire screen
while revealing a small portion of the page behind.
<ExampleTabs name="dialog-with-cover" />
### Fullscreen
Use the `size="full"` prop to make the dialog component take up the entire
screen.
<ExampleTabs name="dialog-with-fullscreen" />
### Placement
Use the `placement` prop to change the placement of the dialog component.
<ExampleTabs name="dialog-with-placement" />
### Controlled
Use the `open` and `onOpenChange` prop to control the visibility of the dialog
component.
<ExampleTabs name="dialog-controlled" />
### Store
An alternative way to control the dialog is to use the `RootProvider` component
and the `useDialog` store hook.
This way you can access the dialog state and methods from outside the dialog.
<ExampleTabs name="dialog-with-store" />
### Context
Use the `DialogContext` component to access the dialog state and methods from
outside the dialog.
<ExampleTabs name="dialog-with-context" />
### Nested Dialogs
You can nest dialogs by using the `Dialog.Root` component inside another
`Dialog.Root` component.
<ExampleTabs name="dialog-nested" />
### Initial Focus
Use the `initialFocusEl` prop to set the initial focus of the dialog component.
<ExampleTabs name="dialog-with-initial-focus" />
### Inside Scroll
Use the `scrollBehavior=inside` prop to change the scroll behavior of the dialog
when its content overflows.
<ExampleTabs name="dialog-with-inside-scroll" />
### Outside Scroll
Use the `scrollBehavior=outside` prop to change the scroll behavior of the
dialog when its content overflows.
<ExampleTabs name="dialog-with-outside-scroll" />
### Motion Preset
Use the `motionPreset` prop to change the animation of the dialog component.
<ExampleTabs name="dialog-with-motion-preset" />
### Alert Dialog
Set the `role: "alertdialog"` prop to change the dialog component to an alert
dialog.
<ExampleTabs name="dialog-with-role" />
### Close Button Outside
Here's an example of how to customize the `Dialog.CloseTrigger` component to
position the close button outside the dialog component.
<ExampleTabs name="dialog-with-close-outside" />
### Non-Modal Dialog
We don't recommend using a non-modal dialog due to the accessibility concerns
they present. In event you need it, here's what you can do:
- set the `modal` prop to `false`
- set `pointerEvents` to `none` on the `Dialog.Positioner` component
- (optional)set the `closeOnInteractOutside` prop to `false`
<ExampleTabs name="dialog-non-modal" />
### DataList
Here's an example of how to compose the dialog component with the `DataList`
component.
<ExampleTabs name="dialog-with-datalist" />
## Props
### Root
<PropTable component="Dialog" part="Root" />
|