Skip to content
synccn

Dialog

Modal with focus trap, scroll lock and Escape to close.

Installation

$ pnpm dlx shadcn@latest add @synccn/dialog

First time in this project? Connect synccn with one command.

Usage

import { Dialog } from "@/components/ui/dialog";<Dialog open={open} onOpenChange={setOpen} title="Edit">…</Dialog>

API reference

Generated from the component's TypeScript types, so it always matches the code.

  • openrequired
    boolean

    Whether the dialog is shown.

  • onOpenChangerequired
    (open: boolean) => void

    Called when it should close (Escape, overlay click, close button).

  • title
    React.ReactNode

    Heading; strings also become the accessible name.

  • description
    React.ReactNode

    Supporting text.

  • footer
    React.ReactNode

    Action buttons.

  • size
    "sm" | "md" | "lg"

    Default "md"

    Maximum width.

  • children
    React.ReactNode

    Content to render.

  • className
    string

    Extra classes for the root element.

Dependencies

Read from the component's imports when the site builds. The CLI installs all of these for you.

Helpers

  • lib/utilscn (merges class names)
  • lib/hooksuseEscape (closes on Escape), useFocusTrap (keeps focus inside while open), useIsClient (renders portals only in the browser), useLockScroll (locks page scroll while open), usePresence (animates in and out)

npm packages

Keyboard

  • TaborShift+TabMove focus; it stays inside while open
  • EscClose

Accessibility

  • role dialog with aria-modal; focus moves inside on open and returns to the trigger on close.
  • Page scroll is locked while it's open.

From the source

Read from this component's code when the site builds, so it can't drift.

  • ARIA roles: dialog
  • ARIA attributes: aria-label, aria-modal
  • Keeps keyboard focus inside while open, and returns it when closed
  • Closes with Escape
  • Stops the page behind from scrolling while open
  • Shows a visible focus ring for keyboard users