Skip to content
Klarhimmel UI

Dialog

npx shadcn add @klarhimmel/dialog @klarhimmel/button

Examples

  • Basic

  • Destructive

  • With a validation error

  • Busy: cannot be dismissed while saving

  • Scroll

DetailsAbout, usage, props and more

A modal window that traps focus, closes on Escape and gives focus back. Built on Radix Dialog.

When to use

  • Use for

    A short task or a decision that needs full attention: rename, confirm, delete.

  • Not for

    Long forms or reading. Use a page. Not for hints. Use a Popover.

  • Pairs with

    Button, Field, DialogClose.

Preview

dialog.tsx
import { Theme } from '@/components/klarhimmel/theme/style';
import { Button } from '@/components/klarhimmel/ui/button';
import { Dialog, DialogClose } from '@/components/klarhimmel/ui/dialog';

export default function Example() {
  return (
    <Theme theme="brand">
      <Dialog
        title="Rename the room"
        trigger={<Button>Rename</Button>}
        footer={<DialogClose><Button>Done</Button></DialogClose>}
      >
        …
      </Dialog>
    </Theme>
  );
}

Import

Import

import { Dialog, DialogClose } from '@/components/klarhimmel/ui/dialog';
Files
dialog.tsx, button.tsx, in components/klarhimmel/ui/. With it: editing, icon-button, theme, utils. npm: lucide-react, radix-ui.
Render in
Render it inside <Theme>, once near the root of your app. Tokens and fonts are scoped to it, so outside it the component is unstyled.
Limit
Overlays render into the Theme root with position: fixed. A transform on an ancestor re-parents fixed (a dialog centres in the wrapper) and overflow: hidden clips menus. Render <Theme> at the app root, outside any transformed wrapper.

Anatomy

The parts and how they nest.

Dialog
├─ trigger (your Button)
├─ title + description
├─ children (the body, scrolls)
└─ footer
   └─ DialogClose (wraps a Button)
  • DialogOwns open state and the overlay. Controlled with open, or opened by trigger.
  • title / descriptionProps, not parts. The title names the dialog for assistive tech.
  • footerButtons pinned under the scrolling body.
  • DialogCloseWraps a footer Button so it closes the dialog.

Props

PropTypeDefaultDescription
Dialog.openboolean-Controlled or uncontrolled state.
Dialog.defaultOpenboolean-Controlled or uncontrolled state.
Dialog.onOpenChange(open: boolean) => void-Controlled or uncontrolled state.
Dialog.triggerReactNode-The element that opens it (a Button). Focus returns to it on close. Omit for a controlled dialog.
Dialog.titlestringrequiredRequired: names the dialog.
Dialog.descriptionReactNode-A line under the title: text, or a small row of parts (a key with its copy button).
Dialog.childrenReactNode-
Dialog.footerReactNode-Buttons, pinned under the body.
Dialog.alertboolean-An alert dialog (role=alertdialog) for a decision that cannot be missed, like a delete: clicking outside does not close it, Escape still does.
Dialog.closeLabelstring-The close button's name for screen readers, in the page's language ('Stäng'). Default 'Close'.
Dialog.classNamestring-Extra classes, merged after the component's own.
DialogClose.childrenReactNoderequired

Accessibility

KeyDoes
Tab / Shift+TabCycles inside the dialog; the page behind is unreachable
EscapeCloses and returns focus to the trigger
Enter / SpaceActivates the focused button

With alert set, a click outside does not close it; Escape still does.

Accessibility