Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Shadcn Dialog for React and Tailwind

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

Installation

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

Anatomy

DialogTrigger
DialogOverlay
DialogPositioner
DialogContent
DialogTitle
DialogDescription
DialogClose

Usage

import { Button } from "@/components/ui/button";
import {
  Dialog,
  DialogBody,
  DialogClose,
  DialogContent,
  DialogFooter,
  DialogHeader,
  DialogTrigger,
} from "@/components/ui/dialog";
import {
  Field,
  FieldGroup,
  FieldLabel,
  FieldSet,
} from "@/components/ui/field";
import { Input } from "@/components/ui/input";
import {
  NativeSelect,
  NativeSelectOption,
} from "@/components/ui/native-select";
<Dialog>
  <DialogTrigger asChild>
    <Button variant="outline">Open</Button>
  </DialogTrigger>

  <DialogContent>
    <DialogHeader
      description="Make changes to your project settings."
      title="Edit project"
    />
    <DialogBody>
      <FieldSet>
        <FieldGroup>
          <Field>
            <FieldLabel>Name</FieldLabel>
            <Input placeholder="My Project" />
          </Field>

          <Field>
            <FieldLabel>Main branch</FieldLabel>
            <NativeSelect>
              <NativeSelectOption value="main">main</NativeSelectOption>
              <NativeSelectOption value="develop">develop</NativeSelectOption>
              <NativeSelectOption value="feature/123">
                feature/123
              </NativeSelectOption>
              <NativeSelectOption value="release/1.0.0">
                release/1.0.0
              </NativeSelectOption>
            </NativeSelect>
          </Field>
        </FieldGroup>
      </FieldSet>
    </DialogBody>
    <DialogFooter>
      <DialogClose asChild>
        <Button variant="outline">Cancel</Button>
      </DialogClose>

      <DialogClose asChild>
        <Button>Save</Button>
      </DialogClose>
    </DialogFooter>
  </DialogContent>
</Dialog>

Accessibility

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

Demos

Close Behavior

Close Button

Confirmation

Context

Controlled

Custom Spacing

Final Focus

Initial Focus

Lazy Mount

Multiple Triggers

Nested

No Close Button

Non Modal

Open From Menu

Outside Scroll

Root Provider

Scroll Area

Size

With Tooltip

API Reference

Dialog

PropType
AttributeType

DialogTrigger

button

PropType
AttributeType

DialogOverlay

div

PropType
AttributeType

DialogPositioner

div

PropType
AttributeType

DialogContent

div

PropType
AttributeType

DialogTitle

h2

PropType
AttributeType

DialogDescription

div

PropType
AttributeType

DialogClose

button

PropType
AttributeType

DialogBody

div

PropType
AttributeType
CSS variableType

DialogHeader

div

PropType
AttributeType
CSS variableType

DialogFooter

div

PropType
AttributeType
CSS variableType

DialogRootProvider

PropType
AttributeType

useDialog

PropType

DialogContext

PropType