Dialog
Modal dialog with escape handling and focus support.
Preview
A live, theme-aware example rendered with the published component.
Loading preview…
Import
Import from the focused entry point below, or use the same named export from @tavojs/ui. Both are public APIs; measure the built application when comparing their bundle cost.
tsximport { Dialog } from "@tavojs/ui/dialog";The component import loads compiled component CSS. Enable tavoUi() for your project theme variables, or import @tavojs/ui/theme.css once for the package default theme. The equivalent CSS-safe component alias is @tavojs/ui/css/dialog.
When to use
Use it when
Choose something else when
Examples
These examples include imports and local state where interaction requires it. Render the exported component in a page after completing UI installation. Demo state stays in the mounted component; connect file handling, persistence, and data loading to your application as needed.
Modal content
tsximport { createTavo } from "@tavojs/core";
import { Dialog } from "@tavojs/ui/dialog";
import { Button, Text, Field, TextInput } from "@tavojs/ui";
type State = { open: boolean };
export const DialogExample1 = createTavo<Record<string, never>, State>({
model: () => ({ open: false }),
view: ({ state, model }) => (
<>
<Button id="invite-trigger" onClick={() => model.set("open", true)}>Invite teammate</Button>
<Dialog
open={state.open}
title="Invite teammate"
labelledBy="invite-title"
describedBy="invite-description"
onClose={() => {
model.set("open", false);
document.getElementById("invite-trigger")?.focus();
}}
>
<Text id="invite-description">Enter the email address to invite.</Text>
<Field id="invite-email" label="Email">
<TextInput type="email" use={(input: HTMLInputElement) => { input.focus(); }} />
</Field>
</Dialog>
</>
)
});Common props and defaults
A curated starting point. The complete TypeScript API below includes additional props and compound member contracts.
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | — | Optional class hook applied to the public root element owned by the component. |
open | boolean | — | Controls whether the dialog is visible. |
title | Child | — | Dialog title. |
onClose | TavoEventHandler | — | Close callback for escape or dismiss actions where supported. |
fullScreen | boolean | — | Configures fullScreen for this component. |
closeLabel | Child | — | Configures closeLabel for this component. |
labelledBy | string | — | Configures labelledBy for this component. |
describedBy | string | — | Configures describedBy for this component. |
Complete TypeScript API
Import from @tavojs/ui/dialog. Published exports: Dialog, DialogBody, DialogContent, DialogFooter, DialogHeader, DialogProps, DialogRoot.
DialogProps
| Property | Type | Required | Description |
|---|---|---|---|
children | Child | No | Inherited children attribute accepted by Dialog. |
className | string | No | Optional class hook applied to the public root element owned by the component. |
sx | Sx | No | Inherited sx attribute accepted by Dialog. |
id | string | No | Inherited id attribute accepted by Dialog. |
role | string | No | Inherited role attribute accepted by Dialog. |
style | Record<string, unknown> | No | Inherited style attribute accepted by Dialog. |
title | string & Child | No | Dialog title. |
tabIndex | number | No | Inherited tabIndex attribute accepted by Dialog. |
hidden | boolean | No | Inherited hidden attribute accepted by Dialog. |
disabled | boolean | No | Inherited disabled attribute accepted by Dialog. |
onClick | TavoEventHandler<MouseEvent> | No | Inherited onClick attribute accepted by Dialog. |
onChange | TavoEventHandler<Event> | No | Inherited onChange attribute accepted by Dialog. |
onInput | TavoEventHandler<Event> | No | Inherited onInput attribute accepted by Dialog. |
onKeyDown | TavoEventHandler<KeyboardEvent> | No | Inherited onKeyDown attribute accepted by Dialog. |
onFocus | TavoEventHandler<FocusEvent> | No | Inherited onFocus attribute accepted by Dialog. |
onBlur | TavoEventHandler<FocusEvent> | No | Inherited onBlur attribute accepted by Dialog. |
open | boolean | No | Controls whether the dialog is visible. |
onClose | () => void | No | Close callback for escape or dismiss actions where supported. |
fullScreen | boolean | No | Configures fullScreen for this component. |
closeLabel | Child | No | Configures closeLabel for this component. |
labelledBy | string | No | Configures labelledBy for this component. |
describedBy | string | No | Configures describedBy for this component. |
State ownership and DOM target
| Concern | Contract |
|---|---|
| State | Use open to supply rendered state. Update it through the documented callback or native event handler. |
| DOM target | Root passthrough props target the overlay. Use labelledBy and describedBy for the inner dialog's accessible name and description. |
Anatomy and related components
Limitations
Avoid for simple inline messages; use Alert or Toast.
Use only the documented props, entry points, and compound members. Internal DOM nesting and CSS class names can change without becoming part of the public component contract.
Accessibility
Uses `role="dialog"`, `aria-modal`, escape close, backdrop close, and tab focus trapping.
Uses `role="dialog"`, `aria-modal`, escape close, backdrop close, and tab focus trapping.
Component status
| Contract | Current value |
|---|---|
| Maturity | stable |
| Category | feedback |
| Component import | @tavojs/ui/dialog |
| Explicit CSS import | @tavojs/ui/css/dialog |
| Preview | Interactive preview available on this page |