# Dialog primitive
Source: https://texuli.com/primitives-page/dialog/
# Dialog
A modal window that traps focus, makes the page inert and restores focus on close.
Import
`import * as Dialog from '@texuli/primitives/dialog';`
Pattern
[Dialog (modal) (WAI-ARIA APG)](https://www.w3.org/WAI/ARIA/apg/patterns/dialog-modal/)
Size budget
12.0 KiB gzip for @texuli/primitives/dialog
Reference
`packages/primitives/docs/prim-dialog.md`
## Live demo
Right to left
Loading the Dialog demo…
## Anatomy
Dialog anatomy: each box holds the parts inside it.
- `Dialog.Root``Dialog.Trigger`
- `Dialog.Portal``Dialog.Overlay`
- `Dialog.Content``Dialog.Title`
- `Dialog.Description`
- `Dialog.Close`
## Behavior checks
`tests/behavior/scenarios/dialog.spec.ts` runs **14 rows** against the Dialog scenario on Chromium, WebKit and the Pixel 7. Each row asserts what a user or assistive technology can observe, held to the WAI-ARIA Authoring Practices pattern.
All 14 rows
- contained: the backdrop fills only the container, stays out of the top layer, and the content is on top
- a dialog mounted already open has focus on its first field, and typing reaches it
- the trigger is a button that says it opens a dialog
- the dialog is named by its title and described by its description
- opening moves focus into the dialog
- Tab and Shift+Tab stay inside the dialog
- Escape closes it and focus returns to the trigger
- the Close button closes it
- with a nested dialog open, Escape closes only the top one
- the page behind the dialog is inert while it is open
- the page does not scroll while the dialog is open
- the page scrolls again once the dialog closes
- a pointer press outside closes it
- it reports opening and closing once each, in order
### Limits
- Every row passes on every project; a flaky row gets at most two retries.
- Size: at most 12.0 KiB gzip for `@texuli/primitives/dialog` (`pnpm size`).
- Open-to-focus: p75 at most 50 ms (asserted with `TEXULI_PERF=1`).
Dialog
A modal window that traps focus, makes the page inert and restores focus on close.
- Import
import * as Dialog from '@texuli/primitives/dialog';- Pattern
- Dialog (modal) (WAI-ARIA APG)
- Size budget
- 12.0 KiB gzip for @texuli/primitives/dialog
- Reference
packages/primitives/ docs/ prim-dialog.md
Loading the Dialog demo…
Anatomy
Dialog.RootDialog.TriggerDialog.PortalDialog.OverlayDialog.ContentDialog.TitleDialog.DescriptionDialog.Close
Behavior checks
tests/behavior/scenarios/dialog.spec.ts runs 14 rows against the Dialog scenario on Chromium, WebKit and the Pixel 7. Each row asserts what a user or assistive technology can observe, held to the WAI-ARIA Authoring Practices pattern.
All 14 rows
- contained: the backdrop fills only the container, stays out of the top layer, and the content is on top
- a dialog mounted already open has focus on its first field, and typing reaches it
- the trigger is a button that says it opens a dialog
- the dialog is named by its title and described by its description
- opening moves focus into the dialog
- Tab and Shift+Tab stay inside the dialog
- Escape closes it and focus returns to the trigger
- the Close button closes it
- with a nested dialog open, Escape closes only the top one
- the page behind the dialog is inert while it is open
- the page does not scroll while the dialog is open
- the page scrolls again once the dialog closes
- a pointer press outside closes it
- it reports opening and closing once each, in order
Limits
- Every row passes on every project; a flaky row gets at most two retries.
- Size: at most 12.0 KiB gzip for
@texuli/primitives/dialog(pnpm size). - Open-to-focus: p75 at most 50 ms (asserted with
TEXULI_PERF=1).