Skip to main content

Dialog

StorybookView in Storybook

Explore interactive examples and all component variations in our Storybook.

The Dialog component creates modal dialogs that overlay the main content. Built on Radix UI primitives, it provides accessible modal functionality with customizable content, headers, footers, and actions.

Basic Usage

Confirmation Dialog

Dialog without Close Button

Properties

Dialog

PropertyTypeDescription
openbooleanThe controlled open state of the dialog.
defaultOpenbooleanThe open state of the dialog when it is initially rendered.
onOpenChange(open: boolean) => voidEvent handler called when the open state changes.
modalbooleanThe modality of the dialog. Default: true.

DialogTrigger

PropertyTypeDescription
asChildbooleanChange the default rendered element for the one passed as a child.
childrenReact.ReactNodeThe element that will trigger the dialog.

DialogContent

PropertyTypeDescription
showCloseButtonbooleanWhether to show the close button. Default: true.
classNamestringAdditional CSS classes for custom styling.
childrenReact.ReactNodeThe content of the dialog.

DialogHeader

PropertyTypeDescription
classNamestringAdditional CSS classes for custom styling.
childrenReact.ReactNodeThe header content (typically title and description).

DialogTitle

PropertyTypeDescription
classNamestringAdditional CSS classes for custom styling.
childrenReact.ReactNodeThe title text.

DialogDescription

PropertyTypeDescription
classNamestringAdditional CSS classes for custom styling.
childrenReact.ReactNodeThe description text.

DialogFooter

PropertyTypeDescription
classNamestringAdditional CSS classes for custom styling.
childrenReact.ReactNodeThe footer content (typically action buttons).

DialogClose

PropertyTypeDescription
asChildbooleanChange the default rendered element for the one passed as a child.
childrenReact.ReactNodeThe element that will close the dialog when clicked.

Accessibility

The Dialog component includes comprehensive accessibility features:

  • Focus Management - Focus is trapped within the dialog when open
  • Keyboard Navigation - Escape key closes the dialog
  • Screen Reader Support - Proper ARIA attributes and roles
  • Focus Restoration - Focus returns to trigger element when closed
  • Backdrop Interaction - Clicking outside closes the dialog (when modal)

Common Use Cases

The Dialog component is perfect for:

  • Forms and Settings - Account settings, preferences, configuration
  • Confirmations - Delete confirmations, important actions
  • Information Display - Terms of service, help content, details
  • Data Entry - Creating new items, editing existing content
  • Alerts and Notices - Important announcements, warnings
  • Media Viewers - Image galleries, video players

Best Practices

  1. Clear Purpose - Use dialogs for focused tasks that require user attention
  2. Appropriate Size - Keep content concise and dialog size reasonable
  3. Action Clarity - Make primary and secondary actions clearly distinguishable
  4. Escape Routes - Always provide a way to close or cancel the dialog
  5. Mobile Friendly - Ensure dialogs work well on smaller screens
  6. Loading States - Show loading indicators for async operations
  7. Error Handling - Display validation errors clearly within the dialog