Skip to content

kit-dialog

<kit-dialog id="confirm" aria-label="Confirm action">
<h2>Are you sure?</h2>
<kit-button meta-command="dialog.close" meta-prop-target="confirm">Cancel</kit-button>
<kit-button class="danger">Yes, delete</kit-button>
</kit-dialog>

<kit-dialog> wraps a native <dialog>. The wrapper provides:

  • Declarative open/close via the open property.
  • A built-in dialogModule() that handles dialog.open and dialog.close commands by id.
  • A closeEvent attribute that emits a Kitsune event on close.

It does not replace the platform’s behavior. Focus management, Escape to close, backdrop, and modal inerting all come from the native <dialog>.

@atheory-ai/kitsune-ui

import '@atheory-ai/kitsune-ui/register'
import { dialogModule } from '@atheory-ai/kitsune-ui/integrations'
shell.modules = [dialogModule(), /* others */]
AttributeTypeDefaultNotes
openbooleanfalseWhether the dialog is currently open. Reflects.
modal"modal" | "non-modal""modal"modal calls showModal(); non-modal calls show(). Reflects.
close-eventstring—If set, emits a meta:event of this type when the dialog closes.
idstring—The id used by dialog.open / dialog.close commands to target this dialog.
MethodNotes
show()Opens the dialog (modal or not, based on modal attr).
close(returnValue?: string)Closes the dialog with an optional return value.
EventDetailFires
kit-dialog-close—When the dialog closes (Escape, native button, programmatic). Composed and bubbles.
meta:event{ type: <closeEvent> }When the dialog closes, only if close-event is set. Composed and bubbles.
PropertyDefault
--kit-color-surfaceCanvas
--kit-color-textCanvasText
--kit-color-borderCanvasText
--kit-radius-md0.5rem
--kit-space-41rem
--kit-focus-ringHighlight

Style the backdrop with ::backdrop on the inner <dialog>, but you may need to use the ::part(backdrop) pattern in a future version. Today, override :host dialog::backdrop from the parent.

The simplest pattern. With dialogModule() installed:

<kit-button meta-command="dialog.open" meta-prop-target="my-dialog">Open</kit-button>
<kit-dialog id="my-dialog">
<h2>Hello</h2>
<kit-button meta-command="dialog.close" meta-prop-target="my-dialog">Close</kit-button>
</kit-dialog>

No JS handler needed. dialogModule() finds the dialog by id and calls show()/close().

const dialog = document.getElementById('my-dialog') as KitDialogElement
dialog.show()
// later
dialog.close()

Or via the runtime:

await shell.runtime.command({ type: 'dialog.open', payload: { target: 'my-dialog' } })
await shell.runtime.command({ type: 'dialog.close', payload: { target: 'my-dialog' } })
<kit-dialog id="confirm" close-event="confirm.dismissed">
<!-- ... -->
</kit-dialog>

When the dialog closes (Escape, button, programmatic), it dispatches a composed meta:event with type: 'confirm.dismissed'. The boundary picks it up and emits a runtime event.

This is a one-line way to track “dialog dismissed” interactions.

Native pattern for confirms:

<kit-dialog id="confirm" aria-label="Confirm action">
<form method="dialog">
<p>Delete this note?</p>
<menu>
<kit-button type="submit" value="cancel">Cancel</kit-button>
<kit-button type="submit" value="confirm" class="danger">Yes</kit-button>
</menu>
</form>
</kit-dialog>

The dialog’s close event has returnValue set to the clicked button’s value. The native dialog handles closing automatically.

  • showModal() traps focus, inerts the rest of the page, and announces as a dialog.
  • Escape closes the dialog (browser default).
  • Use a real <h2> heading inside; it acts as the dialog’s accessible name when it has aria-labelledby (which the underlying <dialog> infers in modern browsers).
  • Don’t add custom focus traps — the native dialog already does it.

Use @atheory-ai/kitsune-ui/elements/kit-dialog for the standalone class or /components/kit-dialog for createKitDialogComponent. Both imports are registration-free; only /register registers the catalog. The factory borrows a compatible host session and preserves this renderer’s native controls/slots. See supplied participation for property bindings, fixed JSON interactions, working drafts and cleanup.

Set controlledClose=true and bind open through the application’s declared query. Escape, public close() and method="dialog" form submission emit kit-dialog-dismiss with {returnValue} while the native dialog remains open. Host policy can show a dirty/unknown-outcome review; an authoritative open=false closes silently. runtimeBlocked suppresses requests. The supplied component factory projects kit-dialog-close-request and selects controlled behavior when configured. Keep legacy imperative dialogModule integration separate from that controlled writer.

Use native autofocus and keyboard behavior. Optional returnFocus and fallbackFocus properties accept trusted local HTMLElement references; a heading/root fallback needs tabindex="-1". Native close normally restores its invoker, and the selected fallback handles a lost or unfocusable invoker. These references are not serialized artifact properties. Ordinary removal closes silently; compatible managed moves preserve the native top layer. Queued old close events do not close a newer cycle.

Closing can retain the mounted form and cancel advisory validation. It does not undo a dispatched command, clear an unknown request, automatically inspect a receipt or resend it. Local inputs remain distinct from durable recovery. Native Tab navigation can visit browser chrome; no scripted focus trap is installed. Nested native popovers retain their own Escape behavior.

The packaged skillex/references/dialogs.md guide and skillex/testing/dialog.js browser recipe cover the bounded pattern. Qualify the actual host’s dirty choices, focus/caret retention, navigation/removal, pending receipts and cleanup. Current evidence is Chromium; cross-browser and full screen-reader audits remain separate.