1. Docs
  2. components
  3. Dialog

Dialog

A window overlaid on either the primary window or another dialog window, rendering the content underneath inert.

Installation

Copy and paste the following code into your project.

Update the import paths to match your project setup.

Usage

Single import

import { Button } from "~/components/ui/button";
import { Dialog } from "~/components/ui/dialog";
<Dialog.Root>
  <Button>Open</Button>
 
  <Dialog.Overlay>
    <Dialog.Modal>
      <Dialog.Content>
        <Dialog.Header>
          <Dialog.Title>Are you absolutely sure?</Dialog.Title>
          <Dialog.Description>
            This action cannot be undone. This will permanently delete your
            account and remove your data from our servers.
          </Dialog.Description>
        </Dialog.Header>
      </Dialog.Content>
    </Dialog.Modal>
  </Dialog.Overlay>
</Dialog.Root>

Multiple imports

import { Button } from "~/components/ui/button";
import {
  DialogContent,
  DialogDescription,
  DialogHeader,
  DialogModal,
  DialogOverlay,
  DialogRoot,
  DialogTitle,
} from "~/components/ui/dialog";
<DialogRoot>
  <Button>Open</Button>
 
  <DialogOverlay>
    <DialogModal>
      <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>
    </DialogModal>
  </DialogOverlay>
</DialogRoot>

Examples

Dialog

Alert Dialog

Use the role="alertdialog" prop on the <Dialog.Content> element to make an alert dialog. Also, make sure to set the isDismissable prop to false on the <Dialog.Overlay> or <Dialog.Modal> to prevent the dialog from being dismissed by clicking outside of it.

Sheet

Use the side prop on the <Dialog.Modal> element to make a sheet dialog.

API Reference

Root

PropTypeDefault
defaultOpen
boolean
false
isOpen
boolean
false
onOpenChange
function

Content

PropTypeDefault
side
enum
"center"
role
enum
"dialog"
isBlurred
boolean
false
isDismissable
boolean
true
isKeyboardDismissDisabled
boolean
false