Getting started

Actions

Forms

Layout

Navigation

Overlays

Feedback

Data display

Controllers

Helpers

Recipes

Dialog

Dialogs interrupt the page to capture a decision or short form. They trap focus and return it when dismissed.

Try it

Usage

Register dialogs with installDialogs, then open them imperatively via openDialog or a trigger with data-dialog-open. Compose title, body, and actions with the sub-components.

import {
  RuiDialog,
  RuiDialogTitle,
  RuiDialogBody,
  RuiDialogActions,
  RuiDialogClose,
  installDialogs,
  openDialog,
} from '@ecopages/radiant-ui/dialog';

installDialogs();

<RuiDialog id="edit-profile" label="Edit profile">
  <RuiDialogTitle>Edit profile</RuiDialogTitle>
  <RuiDialogBody>Update your display name and email.</RuiDialogBody>
  <RuiDialogActions>
    <RuiDialogClose>Cancel</RuiDialogClose>
    <button type="button">Save</button>
  </RuiDialogActions>
</RuiDialog>

Custom markup

<rui-dialog> coordinates any light-DOM tree that matches its query contract. The Rui* helpers stamp these targets; they are not required.

import '@ecopages/radiant-ui/dialog';

<rui-dialog open label="Edit profile">
  <div data-ref="root" class="rui-dialog">
    <div data-ref="backdrop" class="rui-dialog__backdrop"></div>
    <div data-ref="dialog" class="rui-dialog__surface" role="dialog" aria-modal="true" tabindex={-1}>
      <button type="button" data-dialog-close class="rui-dialog__close"></button>
      <div data-dialog-title class="rui-dialog__title">Edit profile</div>
      <div data-dialog-body class="rui-dialog__body">Update your display name and email.</div>
    </div>
  </div>
</rui-dialog>;

BEM classes are presentation-only. Set alert on the host for role="alertdialog" on [data-ref="dialog"].

Alert dialogs

Set alert to true for destructive confirmations. Alert dialogs limit tab order to the controls inside RuiDialogActions, and toggling alert updates the role and the tab loop live. RuiDialogClose without children is the corner icon button, labelled Close; with children it is an in-flow ghost button named by its text, so it sits in RuiDialogActions beside other buttons.

Delete project?
This removes the project and its files. This cannot be undone.

Return focus on close

Focus returns to the element that opened the dialog, also when the dialog closes while a popup inside it is open.

Popups inside a dialog

Select, combobox, menu button, popover, hover card, tooltip, date field and date range picker work inside a dialog; the tests in dialog-composition*.test.tsx drive each with real clicks and keys.

  • Stacking: a popup that opens from inside the dialog renders above it. rui-popover and rui-hover-card portal by default, and from inside a dialog they portal into the dialog surface (any [aria-modal="true"] or modal <dialog> ancestor of the anchor) instead of document.body, which would sit below the dialog. A portal-container you set wins. Positions stay correct when the surface is a containing block for fixed elements, such as the dialog's own enter transition or a modal centred with transform. Select, combobox, menu button, tooltip and the date pickers stay in place.
  • Pointer: choosing an item in a popup does not close the dialog. A click inside the dialog outside the popup closes the popup and keeps the dialog. A click on the backdrop that closes a popup (select, combobox, menu, popover, calendar) closes only that popup; the next backdrop click closes the dialog. A trigger that stays expanded, such as an always-open combobox, never keeps the backdrop from closing the dialog, and a hover card, which a press does not close, does not count.
  • Keyboard: Escape closes the top-most layer, so a popup, a tooltip or a hover card closes before the dialog; a combobox with text clears first. Focus returns to the popup trigger, and when the dialog closes it returns to the opener. Tab and Shift+Tab stay in the dialog. Arrow, Home, End and typing keys go to a text field, slider, listbox or tab list, not to the dialog.
  • Text fields: Escape in a text field closes the dialog.
  • Scroll: the page stays locked until the last open dialog closes; a long select list scrolls inside the list.
  • Toasts: a toast shows above the dialog, takes no focus and is not closed by Escape; Escape closes the dialog.
  • Nesting: set open on a rui-dialog inside another to stack them. Escape, the backdrop and the close button act on the inner one first, and focus returns to the inner opener. openDialog and data-dialog-open keep one dialog open and close the current one.
  • Popups that portal into the dialog surface inherit its text color, font and alignment, can be reached by descendant selectors on the dialog (.my-dialog button), join the dialog's Tab order at the end of the surface, and are not under document.body.
  • The page behind the dialog is not made inert; the focus trap, aria-modal and the backdrop keep keyboard and pointer inside.

Theming

Dialog surfaces map to semantic surface roles, never Tailwind palette steps. Override --rui-dialog-* on rui-dialog.

PartDefaultOverride
Backdropoverlay scrimtheme --color-overlay
Surface fill / radius / shadow--background, --radius-container, --shadow-modal--rui-dialog-surface, --rui-dialog-radius, --rui-dialog-shadow
Surface padding / max width--space-inset, 28rem--rui-dialog-padding, --rui-dialog-max-width
Narrow viewport inset1rem--rui-dialog-inset-x
Titleon-backgroundtheme
Close buttonon-surfacetheme
rui-dialog {
  --rui-dialog-max-width: 40rem;
  --rui-dialog-padding: var(--space-6);
}

Accessibility

  • Every dialog needs an accessible name via label or RuiDialogTitle.
  • Use alert for confirmations that require an explicit decision before continuing.
  • Do not open a dialog without a clear way to dismiss it; provide a close action.

API

RuiDialog is a custom element (<rui-dialog>) with a composition-first surface. Pass title / actions for the composite API, or compose the view helpers as children.

Attributes (<rui-dialog>)

AttributeTypeDefaultDescription
openbooleanfalseWhether the dialog is open.
alertbooleanfalseUses role="alertdialog" for workflow-interrupting confirmations.
labelstring''Accessible name when there is no visible title.

Light-DOM contract

TargetRequiredHost writesAuthor owns
[data-ref="root"]yeshidden when closedthe wrapper node
[data-ref="backdrop"]yes—the scrim node; click dismisses
[data-ref="dialog"]yesaria-labelledby, aria-label, aria-describedbyrole, aria-modal, tabIndex (view seeds these)
[data-dialog-title]noid, aria-labelledby wiringvisible title text
[data-dialog-body]noid, aria-describedby wiringbody content
[data-dialog-close]no—dismiss control; click emits rui-close

Do not set hidden on [data-ref="root"] or aria-* on [data-ref="dialog"]. Nested hosts: none.

Events

EventDetailDescription
rui-close{ reason: 'escape' | 'backdrop' | 'dismiss' }Emitted when the dialog is dismissed.

View helpers

ComponentTarget stampedNotes
RuiDialogDialogShell targetsPass title / actions for composite API, or compose helpers as children.
RuiDialogTitle[data-dialog-title], data-ref="title"Visible accessible name.
RuiDialogBody[data-dialog-body], data-ref="description"aria-describedby target.
RuiDialogActions—Action row; not queried by the host.
RuiDialogClose[data-dialog-close], data-ref="close"Emits rui-close with reason dismiss. Corner icon button without children, ghost rui-button with children.

CSS classes

Public BEM classes (documented via @cssclass):

ClassDescription
.rui-dialogRoot; hidden until open.
.rui-dialog__backdropScrim using the overlay role.
.rui-dialog__surfaceModal panel: background + rounded-container + shadow-modal.
.rui-dialog__titleDialog title; aria-labelledby target.
.rui-dialog__bodyDialog body; aria-describedby target.
.rui-dialog__actionsRight-aligned action row.
.rui-dialog__closeCorner icon dismiss button; not stamped on the text form.

Theme roles

PartCSS variables consumed
Backdrop--overlay
Surface--background, --on-background, --shadow-modal, --radius-container, --p-inset
Close button--on-surface