Dialog

A modal window with a title, a description and actions.

Installation

pnpm dlx shadcn@latest add checkfu/uicontext/dialog

Usage

import { Button } from "./ui/uicontext/components/Button.ts"import { Dialog, DialogFooter, DialogHeader } from "./ui/uicontext/components/Dialog.ts"
const Message = UiSchema.TaggedEnum({ ClickedOpen: {}, ClickedClose: {} })// `open` lives in your Model: ClickedOpen sets it, ClickedClose clears itexport const ShareDialog = (h: Html.H<typeof Message.Type>, open: boolean) =>	h.div.children(		Button(h).on("click", Message.ClickedOpen()).children("Share"),		Dialog(h, {			open,			onClose: Message.ClickedClose(),			labelledBy: "share-title",			children: [				DialogHeader(h, { title: "Share this view", titleId: "share-title" }),				DialogFooter(h, [Button(h).on("click", Message.ClickedClose()).children("Done")]),			],		}),	)

Examples

With a form

Enter submits. An invalid email keeps the dialog open and says what to fix.

No invitations sent yet.

Alert

For a destructive confirmation: alert makes it an alertdialog, and focus starts on the safe choice.

“Overdue invoices”, shared with 6 people

API reference

DialogView function

Options

Dialog options
NameTypeDefaultDescription
keystring—Names the dialog among others in the same view; label (or labelledBy) by default, so give a key when the label changes while the dialog is open
openrequiredboolean—Whether the dialog shows. The caller keeps it.
onCloserequiredMessage—Sent for Escape and presses on the dimmed page; the Model closes the dialog, or keeps it open
labelstring—The dialog's accessible name, when it has no DialogTitle
labelledBystring—The ids of the elements that name and describe it, in place of label
describedBystring—The id of the element that describes it, such as DialogHeader's description.
alertboolean—An alertdialog: it interrupts to ask for an answer (a confirmation), rather than holding a task
size"sm" | "md" | "lg"mdThe dialog's width; md by default.
childrenrequiredView.Children—What the dialog holds: usually DialogHeader, the body and DialogFooter.
styleStyle—StyleX styles applied after the dialog's own.
instantboolean—Opens and closes at once, without fading or growing: for a dialog people open many times a day from the keyboard, such as a command menu.

DialogHeaderView function

Options

DialogHeader options
NameTypeDescription
titlerequiredstringThe dialog's title, which names it.
titleIdstringThe title's id, for the dialog's labelledBy.
descriptionstringA sentence under the title on what the dialog is for.
descriptionIdstringThe description's id, for the dialog's describedBy.

Accessibility

  • A modal <dialog> in the top layer: focus moves inside and stays there, and the page behind takes no presses and is hidden from screen readers.
  • Escape and a click on the dimmed page send onClose; your Model decides whether it closes. An alert dialog closes only on Escape or its buttons.
  • Menus opened from inside it and toasts posted while it's open show above it and stay usable.
  • Name it with a title and describe it with labelledBy and describedBy, or give it a label.

Source