Overlays & Actions
Dialog
Modal dialog with backdrop, centered panel, default close control, Escape + focus return, `presentation="slot"` for custom layouts (Alert Dialog, full-screen previews). Reveal the right amount of context without losing the user's place in the interface. Keep the trigger, content and dismissal behavior working as one interaction. Import it from @/components/kamod-ui/dialog.
Source · Design reference · API reference · Theming · Styles
Interactive preview
Preact example Local preview theme · Responsive styles follow the preview widthFull widthInstallation
Install @kamod-ch/ui, then compose Dialog, DialogTrigger, and DialogContent as in the snippet below. The default modal is centered; for immersive full-viewport layouts use presentation="slot" and apply overlay + panel classes on DialogContent yourself (see Usage). Motion is optional — see With Motion for @kamod-ch/ui-motion.
pnpm add @kamod-ch/uiCopy an example with @kamod-ch/ui or the matching @kamod-ch/ui/… subpath. The code block switches between those two installs. Connect The Global Theme CSS and Tailwind Source Detection before your first render.
Interactive preview
Preact example Local preview theme · Responsive styles follow the preview widthFull widthUsage
Default DialogContent is presentation="modal" (backdrop + centered panel). If your code used to put `fixed inset-0`, `flex items-center justify-center`, and `bg-black/50` on DialogContent itself, you must set `presentation="slot"` — otherwise you get two backdrops and a nested centered shell. Same pattern as AlertDialogContent and the docs “View Markdown” dialog. Width-only classes like sm:max-w-md on modal are fine without slot. lockBodyScroll defaults to true on Dialog.
import { Dialog } from "@kamod-ch/ui";Choose a complete composition from the examples below; required child components and props vary by pattern.
Component Examples & Variants
Explore Dialog in Different Contexts, from the starting pattern to the compositions below. Begin with Custom Layout: Presentation="slot", then compare the examples that match your content, state and layout. These are working patterns to adapt, not a list of interchangeable variant values: check the API Reference before using a prop or combining behaviors. Look at the surrounding labels, supporting text and spacing as well as the component itself.
Read the Result and Its Implementation Together. Use each showcase’s Code view to inspect imports and composition, or its Prompt view to prepare a setup or adaptation brief. Try the narrow preview and local theme controls before connecting real data, and use Reset to return an example to its initial state. Keep layout changes in class utilities where appropriate; follow the Component Styles Guide for hierarchy and the Theming Guide for shared surfaces and colors. The Accessibility Notes explain what to preserve when making those changes.
Custom Layout: Presentation="slot"
Own the Visual Shell without Duplicating It. Use presentation="slot" on DialogContent when the composition provides its own fixed overlay, backdrop and centered panel. This avoids stacking your layout inside the default modal's already-provided overlay and surface.
Keep the dialog's title, description, focus containment and dismissal behavior intact while supplying your own surface; test scrolling and narrow screens as carefully as the centered desktop state.
import { Button, Dialog, DialogClose, DialogContent, DialogTrigger } from "@kamod-ch/ui";
export const Example = () => (
<Dialog>
<DialogTrigger asChild>
<Button variant="outline">Custom overlay</Button>
</DialogTrigger>
<DialogContent
presentation="slot"
class="fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4"
>
<div class="max-w-sm rounded-lg border bg-background p-6 shadow-lg">
<p class="text-sm">Your panel markup only — single portaled root.</p>
<DialogClose asChild>
<Button class="mt-4" variant="outline">
Close
</Button>
</DialogClose>
</div>
</DialogContent>
</Dialog>
);Demo
Keep a Short Editing Task in Context. Place the related fields in FieldGroup beneath the dialog's title and description. The modal provides a focused editing context; your form still owns the values, validation and behavior of its save action.
Connect labels and errors to the fields, choose explicit submit and cancel behavior, and decide whether closing should discard unsaved values before copying the demonstration handlers.
Interactive preview
Preact example Local preview theme · Responsive styles follow the preview widthFull widthBasic
Establish the Dialog's Purpose First. Start with DialogTitle and DialogDescription to give the opened panel a clear purpose and explanation. This minimal composition makes naming and dismissal easier to inspect before adding forms or secondary actions.
Keep the content focused on one task and preserve a discoverable way to close it; use Alert Dialog for a consequential confirmation rather than ordinary supporting information.
Interactive preview
Preact example Local preview theme · Responsive styles follow the preview widthFull widthCustom Close
Make Dismissal Fit the Task. Set showCloseButton={false} when a clearly labeled footer control should provide the visible dismissal action. The custom button becomes part of the dialog's reading order rather than competing with an additional corner control.
Give that control an explicit label and retain the primitive's keyboard behavior; removing the standard corner button should not leave users guessing how to return.
Interactive preview
Preact example Local preview theme · Responsive styles follow the preview widthFull widthScrollable Content
Constrain Long Content to a Readable Region. Give long dialog content its own constrained scroll region beneath the header. This keeps the title available as context while allowing the reader to reach the full explanation without extending the modal beyond the viewport.
Test keyboard scrolling, links near the end and narrow screens, and consider a full page when the content grows into a multi-step or reference-heavy workflow.
Interactive preview
Preact example Local preview theme · Responsive styles follow the preview widthFull widthDestructive Actions
Keep Confirmation Specific to the Pending Operation. Place a cancel action beside a clearly labeled destructive confirmation in the footer. The visual hierarchy should distinguish leaving the dialog from executing the operation while the description explains what the confirmation affects.
If the panel only asks users to confirm a risky decision, compare Alert Dialog before building a custom confirmation flow inside a general dialog.
Interactive preview
Preact example Local preview theme · Responsive styles follow the preview widthFull widthProps and Data
Configure Dialog using the contracts below. Read the documented options alongside the Source Definitions to understand which values your application supplies and which details the component owns. Start with a prop or helper, then follow its type link to inspect the declaration without leaving the page.
Props, slots and variants for this component.
Type cards are extracted from this checkout’s TypeScript source at build time. Props inherited through HTMLAttributes, Omit or variant helpers remain references in those declarations; their fields are not flattened here. Match the reference to your installed version, and check a package’s exports before writing an import type. A type exported by a source file is not necessarily re-exported by @kamod-ch/ui.
Component Props
? means a field can be omitted; it does not promise a fallback value. Existing documented defaults remain alongside the descriptions. For callbacks, check the argument and return types before connecting your own state or services.Dialog
DialogProps
| Prop / type | Description |
|---|---|
children | Configure
|
defaultOpen | Configure
|
dismissible | When false, Escape and an overlay click leave the dialog open. An explicit close control still closes it. Default true.
|
lockBodyScroll | When true, locks document scroll while open (shadcn default).
|
onOpenChange | Configure
|
open | Configure
|
DialogClose
DialogCloseProps
| Prop / type | Description |
|---|---|
asChild | Configure
|
children | Configure
|
data-slot | Configure
|
onClick | Configure
|
ref | Configure
|
DialogContent
DialogContentProps
| Prop / type | Description |
|---|---|
children | Configure
|
class | Configure
|
data-slot | Configure
|
forceMount | Configure
|
getInitialFocus | Override the default focus target when the modal opens (for example AlertDialog cancel).
|
onKeyDown | Configure
|
presentation | `modal` — built-in overlay + centered panel + optional corner close. `slot` — one portaled element only; use when **you** provide overlay + panel (legacy fullscreen `DialogContent` pattern with `fixed inset-0 …`).
|
role | Configure
|
showCloseButton | Configure
|
DialogDescription
DialogDescriptionProps
| Prop / type | Description |
|---|---|
children | Configure
|
class | Configure
|
id | Configure
|
DialogHeader
DialogHeaderProps
| Prop / type | Description |
|---|---|
children | Configure
|
class | Configure
|
DialogPortal
DialogPortalProps
| Prop / type | Description |
|---|---|
children | Configure
|
forceMount | Keep the portal mounted while exit animations run.
|
DialogTitle
DialogTitleProps
| Prop / type | Description |
|---|---|
children | Configure
|
class | Configure
|
id | Configure
|
DialogTrigger
DialogTriggerProps
| Prop / type | Description |
|---|---|
asChild | Configure
|
children | Configure
|
data-slot | Configure
|
onClick | Configure
|
onPointerDown | Configure
|
ref | Configure
|
Data Type Reference
Expand a card to inspect and copy the exact declaration. The code header identifies its repository file; follow imported or inherited types in the Implementation Source when you need the complete dependency chain. Required-field summaries cover fields declared directly in that type. Source-only helpers and inferred schema outputs describe the local implementation, not additional props you can pass to every component.
DialogContextValue
7 declared fieldsDialogContextValueDialog.tsx. Referenced types retain their original names; inspect that file for imports and supporting definitions. Inspect the Complete Definition of DialogContextValue before adapting it.open, setOpen, triggerRef, layerRootRef, defaultTitleId, defaultDescriptionId, dismissibleDialog Props
6 declared fieldsDialogPropsDialog.tsx. Referenced types retain their original names; inspect that file for imports and supporting definitions. Inspect the Complete Definition of DialogProps before adapting it.DialogClose Props
3 declared fieldsDialogClosePropsDialogClose.tsx. Referenced types retain their original names; inspect that file for imports and supporting definitions. Inspect the Complete Definition of DialogCloseProps before adapting it.DialogContentPresentation
DeclarationDialogContentPresentationDialogContent.tsx. Referenced types retain their original names; inspect that file for imports and supporting definitions. Inspect the Complete Definition of DialogContentPresentation before adapting it.DialogContent Props
7 declared fieldsDialogContentPropsDialogContent.tsx. Referenced types retain their original names; inspect that file for imports and supporting definitions. Inspect the Complete Definition of DialogContentProps before adapting it.DialogDescription Props
1 declared fieldDialogDescriptionPropsDialogDescription.tsx. Referenced types retain their original names; inspect that file for imports and supporting definitions. Inspect the Complete Definition of DialogDescriptionProps before adapting it.DialogFooter Props
1 declared fieldDialogFooterPropsDialogFooter.tsx. Referenced types retain their original names; inspect that file for imports and supporting definitions. Inspect the Complete Definition of DialogFooterProps before adapting it.DialogHeader Props
1 declared fieldDialogHeaderPropsDialogHeader.tsx. Referenced types retain their original names; inspect that file for imports and supporting definitions. Inspect the Complete Definition of DialogHeaderProps before adapting it.DialogPortal Props
2 declared fieldsDialogPortalPropsDialogPortal.tsx. Referenced types retain their original names; inspect that file for imports and supporting definitions. Inspect the Complete Definition of DialogPortalProps before adapting it.DialogTitle Props
1 declared fieldDialogTitlePropsDialogTitle.tsx. Referenced types retain their original names; inspect that file for imports and supporting definitions. Inspect the Complete Definition of DialogTitleProps before adapting it.DialogTrigger Props
3 declared fieldsDialogTriggerPropsDialogTrigger.tsx. Referenced types retain their original names; inspect that file for imports and supporting definitions. Inspect the Complete Definition of DialogTriggerProps before adapting it.DialogLabelParts
4 declared fieldsDialogLabelPartsdialogLabelParts.ts. Referenced types retain their original names; inspect that file for imports and supporting definitions. Inspect the Complete Definition of DialogLabelParts before adapting it.hasTitle, hasDescriptionAccessibility
Build the Complete Interaction, Including the Parts Outside Dialog. The notes below distinguish the current implementation from the labels, content and behavior your application supplies. Start with the Live Preview, check the Props and Data Reference, and test the finished composition with real content rather than assuming that an unchanged visual example covers every use case.
Built-in Behavior and Defaults
DialogContent supplies a modal dialog surface, focus containment, Escape dismissal and return focus. DialogTitle and DialogDescription connect its accessible name and description. The default modal presentation includes its own overlay and close control.
Labels and Relationships
Use a title describing the task, followed by a concise explanation where useful. For long structured content, avoid turning every paragraph into one lengthy accessible description. Keep normal headings, labels and reading order inside the dialog.
Use the Built-in Title and Description Relationship. The trigger uses a real button and the dialog keeps its default close control. Add the actual task controls inside the content and verify initial focus for that task.
import {
Button, Dialog, DialogTrigger, DialogContent,
DialogHeader, DialogTitle, DialogDescription,
} from "@kamod-ch/ui";
export function ExportDetails() {
return (
<Dialog>
<DialogTrigger asChild><Button type="button">Export details</Button></DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>About this export</DialogTitle>
<DialogDescription>The export includes the currently visible records.</DialogDescription>
</DialogHeader>
</DialogContent>
</Dialog>
);
}Keyboard and Focus
Open from a meaningful trigger, verify initial focus, then test forward and reverse Tab navigation and Escape. When the trigger disappears after a successful action, your application must choose a sensible surviving focus destination.
States and Integration Details
Use presentation="slot" only when deliberately providing the custom surface the API expects. Avoid nesting a second modal shell around the content. If hiding the default close control, retain another clear, keyboard-operable way to dismiss.
Verify the Complete Interaction
Check Behavior as Well as Markup. Work through these scenarios in the application where the component will be used. Automated checks can help find structural problems; also review the reading experience with a screen reader, keyboard focus and the actual feedback from your application.
- Open, traverse and close without a pointer; confirm focus does not escape into the background.
- Inspect the dialog's name and description, including content with long text or validation errors.
- Submit, dismiss and remove the opener in separate flows; verify return focus and body scrolling recover.
Recheck the result after changing Theme Tokens, translations or class overrides. Include text enlargement, narrow layouts and reduced-motion settings where animation is present. Inspect the Component Source when a behavior differs from your expectation; a role or state attribute does not implement keyboard interaction by itself.
For background, read the WAI-ARIA Authoring Guidance and Keyboard Interface Guidance. These explain the patterns; verify browser and assistive-technology behavior for the implementation and audience you actually support.
You have the pieces. Put them into one real interaction, keep its state in one place, and check the result with the content your application will actually show.
Connect the Foundation
Return to Choose and Compose Components to connect this reference to a working screen. Keep global CSS in one entrypoint and import only the components that screen needs.
Build the Surrounding Screen
Find a neighboring interaction in the Component Library, or start with a complete Block. Replace sample content and destinations before refining the layout; a local class change can stay with the composition.
Make the Result Hold Up
Use shared theme roles for changes that belong everywhere. Then review the whole journey: keyboard focus, long labels, narrow screens and a clear way to recover when something fails.
Keep a link to the source and note your intentional changes. Your next edit should begin with a clear decision, not another search.