Skip to content

Dialog

A modal on the native dialog element: focus stays inside, Escape and a click on the backdrop close it.

On this page
Used for
  • Confirm a delete
  • Rename a project
  • Approve a tool call
  • Edit an agent prompt

Examples

Installation

npx knowns-ui@latest add dialog
For Claude Code, Cursor or Codex: installs it and wires the props to your own data.

Props

open / onOpenChange
boolean / (open) => void
Controlled.
title / description
ReactNode
Heading and supporting text; linked with aria-labelledby / aria-describedby.
footer
ReactNode
Actions on a muted strip at the bottom.
size
"sm" | "md" | "lg"
Default"md"
Max width.
data-autofocus
on any child
Gets focus when the dialog opens instead of the first focusable element.

What it handles

  1. 01Wraps the native dialog element, so showModal gives a focus trap, top-layer stacking and Escape to cancel without extra code.
  2. 02Takes open and onOpenChange, so Escape, the Close button and a click on the backdrop all report false to you.
  3. 03Names itself from title and describes itself from description through aria-labelledby and aria-describedby.
  4. 04Focuses the first control on open, or any element marked data-autofocus, which suits a confirm dialog that should land on Cancel.
  5. 05Puts the actions in the footer slot on a muted strip, and sets width with size sm, md or lg.
  6. 06Opens as a bottom sheet below 640px when sheet is set, full width with a rounded top edge.

States

First render
Nothing. A closed dialog costs nothing on screen
none
Open
The panel fades in rising 4px while the backdrop fades; it leaves the same way, quicker
180ms, ease out
Open as sheet on a phone
The panel slides up from the bottom edge and back down on close
180ms, ease out
Close button hover
The ghost button background changes
120ms, ease out
Reduced motion
The panel and backdrop only fade, with no rise or slide
0ms

Works with

When to use

When to use

  • Focused tasks or confirmations that must be finished or dismissed before going on.

When not to use

  • Small extra details next to a control: use Popover.
  • Status messages: use Toast.

Using with AI

Use Copy page for AI above to give your assistant this page, Copy prompt under the install command to have it installed and wired to your data, or connect the Knowns UI MCP server and just ask:

  • Add the Knowns UI Dialog to my app and wire it to my own data.
  • I need focused tasks or confirmations that must be finished or dismissed before going on. Set that up with the Knowns UI Dialog.
  • Which Dialog props do I need for a minimal setup? Show me a short example.

With the server connected, your assistant calls get_component({ name: "dialog" }) and search_docs({ query: "dialog" }).

Need help?

Stuck on Dialog, or found something off? We read every message.