Documentation

Dialog

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

WebStableSuperpositions

Web uniquement — React, depuis @krizaka/ui/dialog. Stable : son API ne change qu’à une version majeure.

Quand l’utiliser

  • 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}.

Quand ne pas l’utiliser

  • For information next to an element, without blocking the page.À la place : Popover
  • For a message that needs no answer.À la place : 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.À la place : Confirm button

Installation

Installer

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

Styles

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

Importer

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

Exemples

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

PropTypeDéfautDescription
cancelLabelrequisstring—The words of the cancel button (it takes the focus at open) — passed translated.
confirmLabelrequisstring—The words of the confirm button — passed translated.
onConfirmrequis() => void | Promise<unknown>—Runs on confirm. A promise keeps the dialog open and the button loading until it settles.
titlerequisReactNode—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.

PropTypeDéfautDescription
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".

PropTypeDéfautDescription
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.

Accessibilité

  • 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.

Clavier

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

Bonnes pratiques

  • 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.

Générée depuis le code de @krizaka/ui 2.0.0-beta.6 : son meta.ts, ses exemples et ses types.Modifier cette documentation sur GitHub

Sur cette page