Dialog
Enhance an authored native dialog with focus management. Custom element
<ui-dialog> <button class="ui-button" data-ui-part="trigger" type="button" command="show-modal" commandfor="release-dialog">Open dialog</button> <dialog id="release-dialog" aria-labelledby="release-dialog-title" aria-describedby="release-dialog-description"> <header> <h2 id="release-dialog-title">Publish release?</h2> <p id="release-dialog-description">Confirm the public package.</p> </header> <section> <p>Package checks have passed.</p> </section> <footer> <button class="ui-button" data-ui-variant="secondary" data-ui-part="close" type="button" command="close" commandfor="release-dialog" value="cancel">Cancel</button> <button class="ui-button" data-ui-part="close" type="button" command="close" commandfor="release-dialog" value="confirm">Confirm</button> </footer> </dialog></ui-dialog>Install
import '@timelessui/components/css/tokens.css'import '@timelessui/components/css/button.css'import '@timelessui/components/css/dialog.css'import '@timelessui/components/define/ui-dialog'Anatomy
Parts are authored in your own markup and identified by the selector below, so your CSS can target the same anatomy without loading Timeless styles. Required parts must be present for the component to work. Private data-ui-internal-* hooks are written by the runtime and must never be authored.
| Part | Required | Selector | Purpose |
|---|---|---|---|
trigger | Yes | [data-ui-part~='trigger'] | Native button that opens the dialog. Add command="show-modal" and commandfor naming the panel id to open it from markup, before any script runs. Timeless reads those attributes and stands down; it never writes them, because a generated attribute would only work once the bundle had loaded. |
panel | Yes | dialog | The native <dialog> element. Author it, do not generate it. Give it an explicit id when a trigger or close button invokes it, since an invoker can only name an id the author wrote. |
close | No | [data-ui-part~='close'] | Optional explicit close button inside the panel. Add command="close" and commandfor to close it from markup; the platform then also copies the button value into returnValue. |
Attributes
Every value below is implemented by the stylesheets this component ships. Boolean attributes are presence-based: author the attribute with no value, or omit it.
| Attribute | Values | Default | Description |
|---|---|---|---|
kind | dialog · alert | dialog | Whether the panel is a regular dialog or an alert dialog. alert resolves to role="alertdialog", for a destructive confirmation the user must answer. |
Element API
Attributes above are the authoring surface. These are the DOM properties and events the registered element adds once it upgrades.
<ui-dialog>
| Property | Type | Notes |
|---|---|---|
kind | 'dialog' | 'alert' | Reflects the kind attribute, documented above. |
This element dispatches no component events.
Styling
Root identity: ui-dialog. Required stylesheets: tokens.css, button.css, dialog.css.
This component adds no custom properties of its own. Restyle it through the design tokens or your own CSS.
Design tokens this component reads (30)
These are global Atmosphere tokens. Change them once at the theme level rather than per component.
--ui-accent · --ui-bg-accent · --ui-bg-accent-active · --ui-bg-accent-hover · --ui-bg-control · --ui-bg-control-active · --ui-bg-control-hover · --ui-bg-control-muted · --ui-bg-danger · --ui-bg-danger-active · --ui-bg-danger-hover · --ui-bg-surface · --ui-bg-surface-subtle · --ui-duration-fast · --ui-ease-standard · --ui-fg · --ui-fg-muted · --ui-focus · --ui-line · --ui-radius-control · --ui-radius-lg · --ui-shadow-control-accent · --ui-shadow-control-active · --ui-shadow-control-danger · --ui-shadow-floating · --ui-shadow-outline-control · --ui-space-2 · --ui-space-3 · --ui-space-4 · --ui-space-5
Accessibility
Keep the native elements, roles, and relationships shown in the example. Timeless adds only the state and keyboard coordination the platform does not already provide, and it never supplies your accessible names — those depend on your content.
Follows the Modal Dialog pattern from the ARIA Authoring Practices Guide.
| Key | Action |
|---|---|
| Escape | Close the dialog. Handled by the native <dialog> element, not by Timeless. |
Focus trapping, the backdrop, and the top layer all come from showModal(). Timeless moves initial focus into the panel and returns it to the trigger on close. Give the panel an accessible name with aria-labelledby. A dialog invoker gets no implicit aria-expanded from the platform, so Timeless keeps writing it on both the authored-command and click paths.
Before JavaScript runs
The markup above is complete and usable on its own: native controls submit, labels associate, and authored ARIA is already correct. Registration adds state synchronisation, focus management, and keyboard coordination on top of it.
More examples
Open Dialog in StoryLite for variants, controls, and manual testing.