Documentation

Dialog

A window over the page — centred, a bottom sheet or a side panel — and AlertDialog for a confirmation.

WebStableOverlays

Web only — React, from @krizaka/ui/dialog. Stable: its API only changes in a major version.

When to use

  • For a short task that must be finished or cancelled before going back: invite someone, edit a title.
  • AlertDialog to confirm a destructive or irreversible action, with an async onConfirm.
  • Sheet (bottom) on phones, placement="right" for a side panel of details.
  • A gate the user must answer (age, terms): hideClose and dismissible={false}.

When not to use

  • For information next to an element, without blocking the page.Use instead: Popover
  • For a message that needs no answer.Use instead: Toast
  • For a long form or a flow of several steps: give it its own page.
  • To confirm the deletion of one item in place.Use instead: Confirm button

Installation

Install

npm install @krizaka/ui@beta @krizaka/tailwind@beta @krizaka/tokens@beta tailwindcss

Styles

@import "tailwindcss";
@import "@krizaka/tailwind";
@import "@krizaka/ui/tailwind.css";

Import

import { Dialog, Sheet, AlertDialog } from "@krizaka/ui/dialog";

Examples

Centred

A short form, size="md".

Bottom sheet

placement="bottom": a sheet on a phone, centred from sm up.

Side panel

placement="right": full height, for details.

Sheet with a form

Sheet, size="lg".

Alert dialog

AlertDialog tone="danger" with an async onConfirm.

Gate

No close button: it closes only through its actions.

Props

AlertDialog

PropTypeDefaultDescription
cancelLabelrequiredstring—The words of the cancel button (it takes the focus at open) — passed translated.
confirmLabelrequiredstring—The words of the confirm button — passed translated.
onConfirmrequired() => void | Promise<unknown>—Runs on confirm. A promise keeps the dialog open and the button loading until it settles.
titlerequiredReactNode—The question asked ("Delete this video?"): the dialog's accessible name.
childrenReactNode—More content between the description and the actions.
classNamestring—Classes of the dialog's content, merged last.
containerHTMLElement | null—The element the portal renders into (default: document.body).
defaultOpenbooleanfalseOpen at first, uncontrolled.
descriptionReactNode—What the action does and what it costs: the dialog's description.
onOpenChange((open: boolean) => void)—Called when it opens or closes (never while onConfirm is pending).
openboolean—Open or closed (controlled), with onOpenChange.
tone"danger" | "primary"primarydanger for a destructive action (delete, leave, cancel a payment).
triggerReactNode—The element that opens the dialog (rendered as is, asChild): a Button, an IconButton.

DialogContent

The dialog itself, portalled over a dimmed overlay, with a close button. Give it a Dialog.Title.

PropTypeDefaultDescription
closeLabelstring—The accessible name of the close button — passed translated.
containerHTMLElement | null—The element the portal renders into (default: document.body).
dismissiblebooleantruefalse: Escape and a click outside do not close it (a gate the user must answer: age, terms). It still closes through open / onOpenChange and any Dialog.Close inside. Default true.
hideCloseboolean—Leaves the close button out (the content brings its own way out, or none: see dismissible).
placement"center" | "bottom" | "right"centercenter · bottom (a sheet on a phone, centred from sm up) · right (a side panel, full height).
size"sm" | "md" | "lg"mdsm · md · lg: the width of the dialog.

Sheet

A sheet is a dialog anchored at the bottom (centred from sm up): Dialog.Content placement="bottom".

PropTypeDefaultDescription
closeLabelstring—The accessible name of the close button — passed translated.
containerHTMLElement | null—The element the portal renders into (default: document.body).
dismissibleboolean—false: Escape and a click outside do not close it (a gate the user must answer: age, terms). It still closes through open / onOpenChange and any Dialog.Close inside. Default true.
hideCloseboolean—Leaves the close button out (the content brings its own way out, or none: see dismissible).
size"sm" | "md" | "lg"mdsm · md · lg: the width of the dialog.

Accessibility

  • Radix Dialog: role="dialog" (or alertdialog), aria-modal, named by its title and described by its description.
  • The focus moves into the dialog when it opens and returns to the trigger when it closes; the page behind does not scroll.
  • AlertDialog keeps the focus on the cancel button first.

Keyboard

KeysAction
EscCloses the dialog (unless dismissible={false}).
Tab / Shift+TabMove within the dialog: the focus is trapped while it is open.

Best practices

  • Always a Dialog.Title; a Dialog.Description when the title is not enough.
  • Name the buttons by what they do (“Send the invitation”), the cancel one by what it keeps (“Keep it”).
  • Pass closeLabel translated: it names the close button.

Generated from the code of @krizaka/ui 2.0.0-beta.6: its meta.ts, its examples and its types.Edit this documentation on GitHub

On this page