0.1.0-rc.2

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>

Alert dialogs

Set alert to true for destructive confirmations. Alert dialogs limit tab order to the dialog actions.

Return focus on close

Focus returns to the element that opened the dialog. Avoid stacking multiple modal layers.

Theming

Dialog surfaces map to semantic surface roles, never Tailwind palette steps:

PartCSS roles
Backdropoverlay scrim
Surfacebackground, on-background, rounded-container, shadow-modal
Titleon-background
Close buttonon-surface

Body uses the p-inset spacing token. Override roles at the theme layer, not in component CSS.

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.

Slots

SlotDescription
closeOptional close control (RuiDialogClose).
titleOptional visible dialog title (RuiDialogTitle).
(default)Dialog body (RuiDialogBody).
actionsOptional action buttons (RuiDialogActions).

Events

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

View helpers

ComponentSlots into
RuiDialogTitletitle
RuiDialogBody(default)
RuiDialogActionsactions
RuiDialogCloseclose

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__closeDismiss button.

Theme roles

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