Navigated to /docs/ui/components/dialog

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.

TSX
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

Use Dialog for modal workflows that require focused user attention.

Choose something else when

Avoid for simple inline messages; use Alert or Toast.

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

TSXCreate: src/components/examples/DialogExample1.tsx
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.

PropTypeDefaultDescription
classNamestring

Optional class hook applied to the public root element owned by the component.
openboolean

Controls whether the dialog is visible.
titleChild

Dialog title.
onCloseTavoEventHandler

Close callback for escape or dismiss actions where supported.
fullScreenboolean

Configures fullScreen for this component.
closeLabelChild

Configures closeLabel for this component.
labelledBystring

Configures labelledBy for this component.
describedBystring

Configures describedBy for this component.

Complete TypeScript API

Import from @tavojs/ui/dialog. Published exports: Dialog, DialogBody, DialogContent, DialogFooter, DialogHeader, DialogProps, DialogRoot.

DialogProps

PropertyTypeRequiredDescription
childrenChild

No

Inherited children attribute accepted by Dialog.

classNamestring

No

Optional class hook applied to the public root element owned by the component.

sxSx

No

Inherited sx attribute accepted by Dialog.

idstring

No

Inherited id attribute accepted by Dialog.

rolestring

No

Inherited role attribute accepted by Dialog.

styleRecord<string, unknown>

No

Inherited style attribute accepted by Dialog.

titlestring & Child

No

Dialog title.

tabIndexnumber

No

Inherited tabIndex attribute accepted by Dialog.

hiddenboolean

No

Inherited hidden attribute accepted by Dialog.

disabledboolean

No

Inherited disabled attribute accepted by Dialog.

onClickTavoEventHandler<MouseEvent>

No

Inherited onClick attribute accepted by Dialog.

onChangeTavoEventHandler<Event>

No

Inherited onChange attribute accepted by Dialog.

onInputTavoEventHandler<Event>

No

Inherited onInput attribute accepted by Dialog.

onKeyDownTavoEventHandler<KeyboardEvent>

No

Inherited onKeyDown attribute accepted by Dialog.

onFocusTavoEventHandler<FocusEvent>

No

Inherited onFocus attribute accepted by Dialog.

onBlurTavoEventHandler<FocusEvent>

No

Inherited onBlur attribute accepted by Dialog.

openboolean

No

Controls whether the dialog is visible.

onClose() => void

No

Close callback for escape or dismiss actions where supported.

fullScreenboolean

No

Configures fullScreen for this component.

closeLabelChild

No

Configures closeLabel for this component.

labelledBystring

No

Configures labelledBy for this component.

describedBystring

No

Configures describedBy for this component.

State ownership and DOM target

ConcernContract
StateUse open to supply rendered state. Update it through the documented callback or native event handler.
DOM targetRoot passthrough props target the overlay. Use labelledBy and describedBy for the inner dialog's accessible name and description.

Anatomy and related components

Public compound members: Root, Content, Header, Body, Footer

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

ContractCurrent value
Maturitystable
Categoryfeedback
Component import@tavojs/ui/dialog
Explicit CSS import@tavojs/ui/css/dialog
PreviewInteractive preview available on this page