Captain UI

Dialog

Grows out of the button that opened it and shrinks back into it. Focus is trapped inside and handed back when it closes.

npx shadcn@latest add @captain/dialog
Pro

Atlas, spend today

$12.84 of $40.00

Usage

import { Dialog, DialogTrigger, DialogContent, DialogClose } from "@/components/ui/dialog"

<Dialog>
  <DialogTrigger>Change cap</DialogTrigger>
  <DialogContent title="Daily spend cap" description="Atlas pauses at the cap.">
    …
    <DialogClose>Cancel</DialogClose>
  </DialogContent>
</Dialog>

Props

PropTypeDefaultWhat it does
Dialog openbooleanControlled open state. Pair with onOpenChange.
Dialog defaultOpenbooleanfalseInitial state when uncontrolled.
DialogTriggerbutton propsOpens the dialog and becomes its transform origin.
DialogContent titleReactNodeRequired. Wired to aria-labelledby.
DialogContent descriptionReactNodeWired to aria-describedby.
DialogContent dismissiblebooleantrueClose on a click on the scrim.
DialogClosebutton propsCloses the dialog.

Keyboard

Tab / Shift+Tab
Cycle inside the dialog
Esc
Close and return focus to the trigger

Accessibility

  • role=dialog with aria-modal, aria-labelledby and aria-describedby.
  • Focus moves to the first field (or [data-autofocus]) and is trapped until close.
  • Focus returns to whatever opened it. The page behind cannot scroll.