Skip to the page
Supply UI

Dialog

A window over the page for a task that needs its own space: a form, details, a choice. Closes on Escape or a click outside.

Preview

Use

The code of the preview above
import { useState } from 'react';
import {
  Button,
  Dialog,
  DialogClose,
  DialogContent,
  DialogDescription,
  DialogFooter,
  DialogHeader,
  DialogTitle,
  DialogTrigger,
  Field,
  Input,
} from '@/components/ui';

function DialogDemo() {
  const [name, setName] = useState('Harbour Studio');
  return (
    <Dialog>
      <DialogTrigger render={<Button />}>Rename</DialogTrigger>
      <DialogContent>
        <DialogHeader>
          <DialogTitle>Rename the studio</DialogTitle>
          <DialogDescription>The new name shows on every booking</DialogDescription>
        </DialogHeader>
        <Field label="Name">
          <Input value={name} onValueChange={(v: string) => setName(v)} />
        </Field>
        <DialogFooter>
          <DialogClose render={<Button variant="ghost" />}>Cancel</DialogClose>
          <DialogClose render={<Button variant="primary" />}>Save</DialogClose>
        </DialogFooter>
      </DialogContent>
    </Dialog>
  );
}

This page as text, for an AI

Options

No options of its own.

It also takes the 16 attributes of the element or UI SDK part it draws: className, aria-label, events and the rest.

Parts

What goes inside one.

Without React

With the CSS in parts (/ui/css/), it needs these, besides the ones every page loads:

components/card.csscomponents/tabs.csscomponents/dialog.csscomponents/tab-bar.csscomponents/prose.csscomponents/page-transitions.cssparts/carousel.cssparts/board.css

In the examples

Small screens made with it and the rest of the kit. They work: click, type and choose in them.

Clients
  • Kestrel Studio
  • Lumen Bakery
Add without leaving A dialog takes the details; the list grows behind it

On top of the page: states, do and don’t

A task in a window; drawer slides in from the right for details, sheet rises from the bottom (best on a phone). Everything that opens on top closes with a fade: put what a close button does to the page in afterClose, never onClick, so it runs once the closing is over (the same on AlertDialogClose and DrawerClose). Otherwise the page can take the dialog away mid-fade and it just vanishes.

States. Closed, opening (fades and rises), open, closing (fades before what it changed appears: afterClose). While open, focus is inside and Escape closes it; when it closes, focus goes back to what opened it.

Do

  • Name every dialog, drawer and popover (DialogTitle, DrawerTitle, or aria-label).
  • Use AlertDialog for anything that cannot be undone, with the action named on its button ("Delete 3 files").
  • Use a Drawer on a phone for what a Popover does on a computer.

Don't

  • Don't open a dialog from a dialog; change what the open one shows instead.
  • Don't put the only way to do something in a right-click menu or a tooltip.
  • Don't use a toast for something the person must not miss: that is an Alert on the page.