Skip to content

shadcn.io is not affiliated with official shadcn/ui

Shadcn Dialog for React

A modal window that appears on top of the main content.

Installation

bunx --bun shadcn@latest add https://kit.dev/r/aria/dialog.json

Anatomy

DialogTrigger
DialogOverlay
DialogPositioner
DialogContent
DialogTitle
DialogDescription
DialogClose

Usage

import { Button } from "@/components/ui/button";
import {
  Dialog,
  DialogClose,
  DialogContent,
  DialogDescription,
  DialogFooter,
  DialogHeader,
  DialogTitle,
  DialogTrigger,
} from "@/components/ui/dialog";
import {
  Field,
  FieldGroup,
  FieldLabel,
} from "@/components/ui/field";
import { Input } from "@/components/ui/input";
<Dialog>
  <form>
    <DialogTrigger asChild>
      <Button variant="outline">Open Dialog</Button>
    </DialogTrigger>
    <DialogContent className="sm:max-w-sm">
      <DialogHeader>
        <DialogTitle>Edit profile</DialogTitle>
        <DialogDescription>
          Make changes to your profile here. Click save when you&apos;re done.
        </DialogDescription>
      </DialogHeader>
      <FieldGroup>
        <Field>
          <FieldLabel>Name</FieldLabel>
          <Input defaultValue="Pedro Duarte" name="name" type="text" />
        </Field>
        <Field>
          <FieldLabel>Username</FieldLabel>
          <Input defaultValue="@peduarte" name="username" type="text" />
        </Field>
      </FieldGroup>
      <DialogFooter>
        <DialogClose asChild>
          <Button variant="outline">Cancel</Button>
        </DialogClose>
        <Button type="submit">Save changes</Button>
      </DialogFooter>
    </DialogContent>
  </form>
</Dialog>

Accessibility

KeyDescription
Enter
Activate the focused control.
Space
Activate the focused control.

Demos

Close Button

Replace the default close control with your own button.

No Close Button

Use showCloseButton={false} to hide the close button.

Keep actions visible while the content scrolls.

Scrollable Content

Long content can scroll while the header stays in view.

Rtl

Right-to-left dialog. See the RTL configuration guide for document direction.

API Reference

Dialog

PropType
childrenReact.ReactNode
AttributeType

DialogTrigger

PropType
childrenReactNode
className?string
AttributeType

DialogClose

PropType
childrenReact.ReactNode
className?string
AttributeType

DialogOverlay

PropType
childrenReact.ReactNode
AttributeType

DialogHeader

PropType
childrenReact.ReactNode
AttributeType

DialogTitle

PropType
childrenReact.ReactNode
AttributeType

DialogDescription

PropType
childrenReact.ReactNode
AttributeType

DialogFooter

PropType
childrenReact.ReactNode
AttributeType