Back to Shark UI

Dialog

docs/components/dialog

latest11.2 KB
Original Source

Sections

Components

Utilities

Forms

Hooks

Dialog

Copy Markdown

A dialog for displaying content.

DocsAPI

PreviewCode

Open

Installation#

CLIManual

pnpmbunnpmyarn

pnpm dlx shadcn@latest add @shark/dialog

Anatomy#

Dialog
├── DialogTrigger
└── DialogContent
    ├── DialogHeader
    │ ├── DialogTitle
    │ └── DialogDescription
    ├── DialogBody
    └── DialogFooter
        └── DialogClose

Usage#

import { 
  Dialog, 
  DialogTrigger, 
  DialogContent, 
  DialogHeader,
  DialogTitle, 
  DialogDescription, 
  DialogBody,
  DialogFooter,
  DialogClose,
} from "@/components/ui/dialog";
<Dialog>
  <DialogTrigger />
  <DialogContent>
    <DialogHeader>
      <DialogTitle />
      <DialogDescription />
    </DialogHeader>
    <DialogBody>
    </DialogBody>
    <DialogFooter>
      <DialogClose />
    </DialogFooter>
  </DialogContent>
</Dialog>

Controlled#

Use open and onOpenChange on the root to control the dialog state.

PreviewCode

Open ControlledOpen Uncontrolled

Title & Description#

DialogHeader supports two usage patterns:

Using props#

Pass title and description props directly to DialogHeader.

<DialogHeader title="Dialog Title" description="Dialog description" />

This approach does not require DialogTitle or DialogDescription components.

Using components#

Use DialogTitle and DialogDescription as children for more control.

<DialogHeader>
  <DialogTitle>Dialog Title</DialogTitle>
  <DialogDescription>Dialog description</DialogDescription>
</DialogHeader>

Size#

Use the size prop on DialogContent to control the maximum width of the panel.

PreviewCode

smmdlgxl2xl3xl4xl5xl6xlfullscreen

Examples#

Scrollable#

Use DialogBody to make the content area scrollable while keeping header and footer fixed.

PreviewCode

Open

No Close Button#

Use the showCloseButton={false} prop to hide the close button in the top right corner.

PreviewCode

Open

Close behavior#

Use closeOnInteractOutside and closeOnEscape props to prevent closing on outside click and escape.

PreviewCode

No close on outside clickNo close on Escape

Open from Menu#

Open a dialog imperatively from a menu item using the onSelect handler.

PreviewCode

Open

Non-Modal#

Use modal={false} to allow interaction with elements outside the dialog.

PreviewCode

Open

Initial Focus#

Use initialFocusEl to control which element receives focus when the dialog opens.

PreviewCode

Open

Nested#

Nest dialogs within one another.

PreviewCode

Open

Custom spacing#

Use [--space:--spacing("value")] on DialogContent to adjust internal padding.

Default spacing is --spacing(6).

PreviewCode

Open

You can use breakpoint utilities to change the internal spacing at different screen sizes.

md:[--space:--spacing(6)] lg:[--space:--spacing(8)]

API Reference#

Dialog#

Root context provider. Controls open state and modal behavior.

PropTypeDefault
openboolean-
defaultOpenbooleanfalse
onOpenChange({ open }: OpenChangeDetails) => void-
modalbooleantrue
closeOnEscapebooleantrue
closeOnInteractOutsidebooleantrue
initialFocusEl() => MaybeElement-
finalFocusEl() => MaybeElement-
onEscapeKeyDown(event: KeyboardEvent) => void-
onInteractOutside(event: InteractOutsideEvent) => void-
classNamestring-

DialogTrigger#

Opens the dialog on click. Use asChild for custom trigger elements.

PropTypeDefault
asChildbooleanfalse
classNamestring-

DialogContent#

Holds the dialog panel. Supports size variants from sm to fullscreen.

PropTypeDefault
size`"sm""md"
showCloseButtonbooleantrue
classNamestring-
AttributeDefault
--space--spacing(6)

DialogHeader#

Header area for title and description. Accepts props or children.

PropTypeDefault
titlestring-
descriptionstring-
classNamestring-

DialogBody#

Scrollable body content. Uses ScrollArea for overflow.

PropTypeDefault
classNamestring-

DialogFooter#

Footer area for action buttons.

PropTypeDefault
classNamestring-

DialogTitle#

Accessible title for the dialog. Announced to screen readers.

PropTypeDefault
asChildbooleanfalse
classNamestring-

DialogDescription#

Accessible description for the dialog. Announced to screen readers.

PropTypeDefault
asChildbooleanfalse
classNamestring-

DialogClose#

Closes the dialog on click. Use asChild for custom close elements.

PropTypeDefault
asChildbooleanfalse
classNamestring-

DialogOverlay#

Dimmed overlay behind the dialog panel.

PropTypeDefault
classNamestring-

For a complete list of props, see the Ark UI documentation.

[

Previous page

Date Picker ](/docs/components/date-picker)[

Next page

Drawer ](/docs/components/drawer)

On This Page

InstallationAnatomyUsageControlledTitle & DescriptionUsing propsUsing componentsSizeExamplesScrollableNo Close ButtonClose behaviorOpen from MenuNon-ModalInitial FocusNestedCustom spacingAPI ReferenceDialogDialogTriggerDialogContentDialogHeaderDialogBodyDialogFooterDialogTitleDialogDescriptionDialogCloseDialogOverlay