Prototyper UI

Dialog

A modal dialog with sheet variant built on Base UI

Loading...

Installation

pnpm dlx shadcn@latest add https://prototyper-ui.com/r/dialog.json
npx shadcn@latest add https://prototyper-ui.com/r/dialog.json
yarn dlx shadcn@latest add https://prototyper-ui.com/r/dialog.json
bunx --bun shadcn@latest add https://prototyper-ui.com/r/dialog.json

This will add the following files to your project:

  • components/ui/dialog.tsx

Usage

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

<Dialog>
  <DialogTrigger>Open</DialogTrigger>
  <DialogContent>
    <DialogHeader>
      <DialogTitle>Dialog Title</DialogTitle>
      <DialogDescription>Dialog description.</DialogDescription>
    </DialogHeader>
  </DialogContent>
</Dialog>

Anatomy

<Dialog>
  <DialogTrigger />
  <DialogContent>
    <DialogHeader>
      <DialogTitle />
      <DialogDescription />
    </DialogHeader>
    {/* your content */}
    <DialogFooter>
      <DialogClose />
    </DialogFooter>
  </DialogContent>
</Dialog>
Sub-componentdata-slotPurposeRequired
DialogdialogRoot provider, manages open/close stateYes
DialogTriggerdialog-triggerButton that opens the dialogYes
DialogPortaldialog-portalRenders children into a portalNo
DialogOverlaydialog-overlayBackdrop behind the dialogNo
DialogContentdialog-contentThe dialog popup panelYes
DialogHeaderdialog-headerFlex container for title and descriptionNo
DialogTitledialog-titleAccessible title for the dialogYes
DialogDescriptiondialog-descriptionAccessible description for the dialogNo
DialogFooterdialog-footerFlex container for action buttonsNo
DialogClosedialog-closeButton that closes the dialogNo

Examples

Alert Dialog

Loading...

Sheet

Loading...

Styling

Data Slots

Use data-slot attributes to target specific parts of the dialog:

Slot nameElement
dialogRoot provider (no DOM element rendered)
dialog-triggerThe trigger button
dialog-portalPortal wrapper
dialog-overlayBackdrop overlay
dialog-contentThe popup panel
dialog-headerHeader container (title + description)
dialog-titleTitle heading
dialog-descriptionDescription paragraph
dialog-footerFooter container (action buttons)
dialog-closeClose button(s)

Customization Examples

/* Make dialogs wider by default */
[data-slot="dialog-content"] {
  @apply sm:max-w-lg;
}

/* Custom overlay color */
[data-slot="dialog-overlay"] {
  @apply bg-black/30;
}
{/* Override width via className */}
<DialogContent className="sm:max-w-2xl">
  {/* ... */}
</DialogContent>

API Reference

Dialog

Root component that manages open/close state.

Prop

Type

All Base UI Dialog.Root props are forwarded via ...props.

DialogTrigger

Button that opens the dialog when clicked.

Prop

Type

All Base UI Dialog.Trigger props are forwarded via ...props.

DialogContent

The popup panel rendered inside a portal with an overlay backdrop.

Prop

Type

All Base UI Dialog.Popup props are forwarded via ...props.

DialogHeader

Flex column container for title and description.

Prop

Type

All standard div props are forwarded via ...props.

DialogFooter

Flex row container for action buttons.

Prop

Type

All standard div props are forwarded via ...props.

DialogTitle

Accessible title for the dialog, rendered as a heading.

Prop

Type

All Base UI Dialog.Title props are forwarded via ...props.

DialogDescription

Accessible description rendered below the title.

Prop

Type

All Base UI Dialog.Description props are forwarded via ...props.

DialogClose

Button that closes the dialog when clicked.

All Base UI Dialog.Close props are forwarded via ...props.

DialogOverlay

Backdrop overlay behind the dialog.

Prop

Type

All Base UI Dialog.Backdrop props are forwarded via ...props.

DialogPortal

Renders children into a React portal.

All Base UI Dialog.Portal props are forwarded via ...props.

Accessibility

Keyboard Interactions

KeyAction
EscapeCloses the dialog
TabMoves focus to the next focusable element within the dialog
Shift+TabMoves focus to the previous focusable element within the dialog

ARIA Attributes

  • DialogContent receives role="dialog" (or role="alertdialog" when used as an alert dialog).
  • aria-modal="true" is set when the dialog is modal.
  • aria-labelledby is automatically linked to DialogTitle.
  • aria-describedby is automatically linked to DialogDescription.
  • Focus is trapped inside the dialog while it is open.
  • Focus returns to the trigger element when the dialog closes.

On this page