Skip to Content
NarakUI

Dialog

A modal dialog component for displaying content in an overlay.

Structured

Use variant="structured" with contentPadding="regions" for new dialogs. Dialog.Header holds the title row and Dialog.CloseButton. Dialog.Body scrolls. Dialog.Footer holds the actions; wrap dismiss actions in Dialog.Close asChild. Pass divider on the header and footer to separate them from a form body.

When you render Dialog.Title and Dialog.Description, pass hasAccessibleTitle and hasAccessibleDescription on Dialog.Content.

Controlled

Pass open and onOpenChange to open the dialog from your own state, for example a confirmation before a destructive action.

Default Variant

Omitting variant gives the legacy shell. Use it only to match an existing one-off layout. It has no regions and shows a close button in the top-right corner; pass showCloseButton={false} to hide it. Its panel has a 520px minimum width, so give it w-130 min-w-0 to let it shrink on small screens.

Installation

pnpm dlx shadcn@latest add @narakui/dialog

Add "@narakui": "https://ui.narakcode.dev/r/{name}.json" to components.json, or install directly from https://ui.narakcode.dev/r/dialog.json.

Usage

import { Dialog } from '@/components/ui/dialog';

<Dialog.Root>
  <Dialog.Trigger asChild>
    <Button>Open Dialog</Button>
  </Dialog.Trigger>
  <Dialog.Content variant="structured" contentPadding="regions" hasAccessibleTitle>
    <Dialog.Header>
      <Dialog.Title>Dialog title</Dialog.Title>
    </Dialog.Header>
    <Dialog.Body>Dialog content</Dialog.Body>
    <Dialog.Footer>
      <Dialog.Close asChild>
        <Button>Cancel</Button>
      </Dialog.Close>
    </Dialog.Footer>
  </Dialog.Content>
</Dialog.Root>

Without a visible Dialog.Title, pass aria-label on Dialog.Content. It renders a screen-reader-only title.

Parts

PartTypeDescription
Dialog.Root (Required)DialogRootPropsManages open state and modal behavior
Dialog.TriggerDialogTriggerPropsOpens the dialog. Use asChild with a Button.
Dialog.Content (Required)DialogContentPropsPortal, overlay, and panel
Dialog.HeaderDialogHeaderPropsTitle row, close button, and description
Dialog.BodyDialogBodyPropsScrollable main region
Dialog.FooterDialogFooterPropsRight-aligned action row
Dialog.TitleDialogTitlePropsAccessible dialog title
Dialog.DescriptionDialogDescriptionPropsAccessible dialog description
Dialog.CloseButtonDialogCloseButtonPropsGhost icon button that closes the dialog. aria-label defaults to Close dialog.
Dialog.CloseComponentPropsWithoutRef<typeof Close>Radix close primitive. Use asChild to make a footer button close the dialog.
Dialog.OverlayDialogOverlayPropsBackdrop. Dialog.Content renders it for you.

Dialog.Root Properties

PropTypeDefaultDescription
openboolean—Controlled open state of the dialog
onOpenChange(open: boolean) => void—Callback fired when the open state changes
defaultOpenbooleanfalseDefault open state of the dialog
modalbooleantrueBlocks interaction with content outside the dialog

Dialog.Content Properties

PropTypeDefaultDescription
variant'default' | 'structured''default'Structured lays out Header, Body, and Footer. Default is the legacy shell.
size'md' | 'lg' | 'xl''md'Structured only. md is 440px wide, lg is 640px with a 40vh minimum height, xl is 800px with a 60vh minimum height.
contentPadding'content' | 'regions''content'Structured only. regions moves the padding onto Header, Body, and Footer so dividers run full width. Prefer regions; don't combine with className="p-0".
contentGap'default' | 'none''default'Structured only. Gap between Header, Body, and Footer.
showCloseButtonboolean—Renders the top-right close icon. Defaults to true for the default variant and false for structured.
hasAccessibleTitlebooleanfalseSet when children include Dialog.Title so no hidden title is added
hasAccessibleDescriptionbooleanfalseSet when children include Dialog.Description so no hidden description is added
disablePortalbooleanfalseRender in the current context instead of a portal
hideOverlaybooleanfalseDo not render the dialog's own overlay
overlayZIndex'dialog' | 'drawer''dialog'Stacking layer. Use drawer to show the dialog above a drawer.
overlayDarkerBackgroundbooleanfalseUse a darker overlay background
overlayClassNamestring—Additional CSS classes for the overlay
classNamestring—Additional CSS classes for the panel
onOpenAutoFocus(event: Event) => void—Called when the dialog opens. Default focus is already prevented, so focus the element you want.
onCloseAutoFocus(event: Event) => void—Called when focus returns to the trigger after the dialog closes
onEscapeKeyDown(event: KeyboardEvent) => void—Called when Escape is pressed. Call event.preventDefault() to keep the dialog open.
onPointerDownOutside(event: PointerDownOutsideEvent) => void—Callback fired when clicking outside the dialog
onInteractOutside(event: CustomEvent) => void—Callback fired for any pointer or focus interaction outside the dialog. The event is a PointerDownOutsideEvent or a FocusOutsideEvent.

Region Properties

PropTypeDefaultDescription
dividerbooleanfalseDialog.Header and Dialog.Footer: draws a border between the region and the body
scrollShadowbooleanfalseDialog.Body: fades the top and bottom edges while there is more to scroll. Structured only.
viewportClassNamestring—Dialog.Body: classes for the scrolling viewport when scrollShadow is set
focusRingInsetbooleantrueDialog.Body: adds vertical padding so focus rings are not clipped under contentPadding="regions". Turn off when the body sets its own vertical padding.

Dialog.Overlay Properties

PropTypeDefaultDescription
zIndex (Required)'dialog' | 'drawer'—Stacking layer relative to other modal surfaces
withBackdropBlurbooleantrueBlurs the content behind the dialog
darkerBackgroundbooleanfalseUses a darker scrim