Skip to Content
✨ Just dropped my UI Library — still cooking up some magic! Stay tuned & maybe… hire me  or sponsor me 😉 
DocumentationDialog

Dialog

A flexible and accessible dialog component for creating modal windows with smooth animations. Supports both traditional state management and modern compound component patterns.

Install Dependencies

npx
quickcode-ui add Dialog

Basic State-Controlled Dialog

Standard dialog pattern using React state for control.

Basic State-Controlled Dialog

Compound Component Pattern (DialogTrigger)

Use DialogTrigger for stateless dialog management - no state needed!

Compound Component Pattern (DialogTrigger)

Default Open Dialog

Dialog that opens automatically when component mounts.

Default Open Dialog

Welcome!

This dialog opens automatically when component mounts

This dialog appeared automatically because isOpen started as true.

Prevent Overlay Click Dialog

Critical dialogs that require explicit user action to close.

Prevent Overlay Click Dialog

Custom Styled Dialog

Showcase advanced styling capabilities with custom classes.

Custom Styled Dialog

Props

PropTypeDefaultDescription
childrenReact.ReactNode-Content to display inside the dialog
isOpenboolean-Controlled open state of the dialog
defaultOpenbooleanfalseDefault open state for uncontrolled usage
onOpenChange(open: boolean) => void-Callback fired when open state changes
showCloseButtonbooleantrueWhether to show the close button (positioned absolutely)
closeOnOverlayClickbooleantrueWhether clicking overlay closes the dialog
closeOnEscapeKeybooleantrueWhether pressing Escape key closes the dialog
titlestring-Title text displayed in the dialog header
descriptionstring-Description text displayed below the title
classNamestring-Additional classes for the dialog wrapper
overlayClassNamestring-Additional classes for the backdrop overlay
contentClassNamestring-Additional classes for the dialog content container
headerClassNamestring-Additional classes for the header section
bodyClassNamestring-Additional classes for the body content
titleClassNamestring-Additional classes for the title text
descriptionClassNamestring-Additional classes for the description text

DialogTrigger Props

PropTypeDefaultDescription
childrenReact.ReactNode-The trigger element (button, link, etc.)
asChildbooleanfalseMerge trigger props with child element
classNamestring-Additional classes for the trigger element

Features

  • Flexible Patterns: Traditional state management or modern compound components with DialogTrigger
  • Zero State Compound: DialogTrigger pattern requires no state management - completely automatic
  • Smooth Animations: Powered by Framer Motion with scale, opacity, and position transitions
  • Accessibility First: Full keyboard navigation, focus management, ARIA attributes, and screen reader support
  • Advanced Close Button: Absolutely positioned close button that doesn’t affect content layout
  • Customizable Behavior: Fine-grained control over closing behavior (overlay clicks, escape key)
  • Rich Styling System: Granular className props for every section (overlay, content, header, body, title, description)
  • Body Scroll Lock: Automatically prevents background scrolling when dialog is open
  • Focus Management: Auto-focuses first focusable element and traps focus within dialog
  • Responsive Design: Adapts to all screen sizes with proper mobile handling
  • Dark Mode Ready: Built-in support for light/dark themes
  • TypeScript First: Full TypeScript support with proper typing for all props and patterns

Usage Patterns

Traditional State-Controlled Pattern

const [isOpen, setIsOpen] = useState(false); <Dialog isOpen={isOpen} onOpenChange={setIsOpen}> <p>Content here</p> </Dialog>;

Modern Compound Component Pattern

<Dialog title="My Dialog"> <DialogTrigger asChild> <Button>Open Dialog</Button> </DialogTrigger> <p>Content here</p> </Dialog>
Last updated on