Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go
3.3 KB
Raw Blame

Dialog

Import from @multica/ui/components/ui/dialog.

Usage

Use Dialog for a focused task that needs a modal surface. Use Popover for contextual options and AlertDialog for a consequential confirmation.

Compose Dialog, DialogTrigger, DialogContent, DialogHeader, DialogTitle, DialogDescription, DialogFooter and DialogClose. Dialog has no variant prop; form and long-content examples are compositions of the same component.

Behavior

Provide a title and a concise description. Let the primitive manage focus trapping, Escape, outside dismissal and focus restoration. Use DialogTrigger so focus can return to the opener. Label form fields. Keep the footer reachable with long content and narrow viewports.

Only close a submitting dialog after the operation succeeds. Preserve its input and show an error on failure.

HTML code previews use the focused HtmlPreviewSurface in packages/views/editor/ instead of a portal. Its native dialog promotes the existing inline iframe to the browser's top layer without changing its DOM parent or reloading its document. Keep the preview mounted when switching to source, and defer source updates until it is visible. When returning to inline preview, request a fresh height report even if unchanged; fullscreen reports must not overwrite the inline height. Verify repeated open/close, focus restoration, backdrop dismissal and inline height restoration after content expands or shrinks in a browser; jsdom cannot verify iframe document retention. Escape works when focus is in the parent document; keyboard events inside a cross-origin iframe do not reach it.

Correct

<Dialog>
  <DialogTrigger render={<Button />}>Edit title</DialogTrigger>
  <DialogContent>
    <DialogHeader>
      <DialogTitle>Edit title</DialogTitle>
      <DialogDescription>Update the task title.</DialogDescription>
    </DialogHeader>
    <label>Title<Input defaultValue="Review interface" /></label>
    <DialogFooter>
      <DialogClose render={<Button variant="outline" />}>Cancel</DialogClose>
      <Button onClick={saveThenClose}>Save</Button>
    </DialogFooter>
  </DialogContent>
</Dialog>

Avoid

<div role="dialog" className="fixed inset-0">
  <Input placeholder="Title" />
  <Button onClick={() => { save(); close(); }}>Save</Button>
</div>

A role alone does not supply an accessible name, focus management or dismissal behavior. Do not close before an asynchronous save succeeds.

Motion

Popup and backdrop consume --dialog-enter-duration, --dialog-exit-duration, --dialog-enter-easing and --dialog-exit-easing from packages/ui/styles/tokens.css. The defaults use 100ms with the shared ease-out enter curve (cubic-bezier(0.23, 1, 0.32, 1)). The popup also fades and scales between 95% and 100%.

Changes affect shared Dialog and AlertDialog instances on web and desktop, including compositions that use DialogContent, unless callers override the animation. They do not change Popover, Tooltip, or JavaScript motion constants.

Respect prefers-reduced-motion: popup and backdrop animations are disabled. Open, close and replay the real component; also interrupt it with rapid open/close actions.

Application

Edit the motion tokens in the :root block of packages/ui/styles/tokens.css, then compare both themes and keyboard behavior.