CraftUI

Dialog

A modal with a title bar, a close button and proper focus handling.

Installation

npx shadcn@latest add @runqora/craft-dialog

Usage

import {
  Dialog,
  DialogBody,
  DialogContent,
  DialogDescription,
  DialogHeader,
  DialogTitle,
  DialogTrigger,
} from "@/components/craft/dialog";

<Dialog>
  <DialogTrigger>Open</DialogTrigger>
  <DialogContent>
    <DialogHeader>
      <DialogTitle>World details</DialogTitle>
    </DialogHeader>
    <DialogBody>
      <DialogDescription>Created on May 15.</DialogDescription>
    </DialogBody>
  </DialogContent>
</Dialog>;

To use a CraftUI button as the trigger or a close action, pass it through render: <DialogTrigger render={<Button />}>Open</DialogTrigger>.

Examples

With a form

This dialog is controlled, so it closes when the form submits.

Props

Dialog

Prop

Type

DialogContent

Prop

Type

Accessibility

  • Always include a DialogTitle, which names the dialog for screen readers. DialogDescription is announced as its description.
  • Focus moves into the dialog when it opens and stays there, and it returns to the trigger when the dialog closes.
  • Escape closes the dialog, and so does clicking the backdrop.
  • For a destructive choice, consider initialFocus to start on the safer action.

Customization

Set the width on DialogContent. The dialog always fits a narrow screen, and DialogBody scrolls when the content is tall.

<DialogContent className="max-w-2xl">...</DialogContent>

Dependencies

Source

On this page