Tinyrack

Dialog

Focus-trapped dialog surfaces with five placements.

Contract

AxisValuesDefault
placement on Popupmiddle, top, bottom, start, endmiddle
modal on Rootfocus trap and scroll lock when truetrue
statecontrolled open or uncontrolled defaultOpenclosed

Install

pnpm add @tinyrack/ui

Scroll inside the code area to read long lines.

Styles

@import '@tinyrack/ui/components/dialog.css';

Scroll inside the code area to read long lines.

Imports

import { TRDialog } from '@tinyrack/ui/components/dialog';

Scroll inside the code area to read long lines.

Playground

Usage

Examples

Placements permalink

Use the same compound structure and change only popup placement.

Detached trigger handle permalink

A stable handle connects a trigger and root that do not share an ancestor while Viewport owns mobile containment.

Long modal task with a form permalink

The modal traps focus while open, keeps long content inside the viewport, submits a real form, and restores focus to Open dialog after dismissal.

API

Base UI owns focus trapping, scroll lock, portal, backdrop interaction, restoration, and Escape dismissal. Popup uses one responsive width recipe across all placements. Put long task content in a tr-dialog-body container between Description and the action row so the popup's minmax(0, 1fr) body scrolls while its title and actions remain visible.

Public APIPurpose
TRDialog.Root / TRDialogRootOwns controlled open, uncontrolled defaultOpen, modality, dismissal, and optional handle payload state.
TRDialog.Trigger / TRDialogTriggerOpens the root, or a detached root when given a handle and optional payload.
TRDialog.Portal / TRDialogPortalMoves the layer to document.body or a custom container.
TRDialog.Backdrop / TRDialogBackdropProvides the modal scrim and outside-press target.
TRDialog.Viewport / TRDialogViewportContains long and mobile dialog layouts.
TRDialog.Popup / TRDialogPopupRenders the named dialog, accepts initialFocus, finalFocus, and Tinyrack placement.
TRDialog.Title / TRDialogTitleSupplies the accessible name.
TRDialog.Description / TRDialogDescriptionSupplies the accessible description.
TRDialog.Close / TRDialogCloseCloses the active dialog and restores focus.
TRDialog.createHandle, createDialogHandle, TRDialogHandle<Payload>Connect detached triggers, imperative open/close calls, and typed payloads.

Use modal={false} when outside interaction must remain available, or modal="trap-focus" to trap focus without scroll lock. disablePointerDismissal keeps outside presses from closing the dialog. All parts preserve refs, render, event handlers, classes, styles, and native attributes. Closed portals are SSR-safe and default-open portals hydrate without changing the public structure.