Dialog

A modal overlay that requires user interaction. Traps focus, blocks background content, and closes on Escape.

Primitive: DialogARIA: role="dialog"Keyboard: Escape, Tab trap
Delete project?
This will permanently delete "Project Alpha" and all of its data. This action cannot be undone.
dialog.rs
use stratum_leptos::*;

let (show, set_show) = create_signal(false);

view! {
    <Button on_click=move |_| set_show(true)>
        "Open Dialog"
    </Button>
    <Dialog open=show on_open_change=set_show>
        <DialogTitle>"Delete project?"</DialogTitle>
        <DialogDescription>
            "This action cannot be undone."
        </DialogDescription>
        <Button variant=ButtonVariant::Outline
            on_click=move |_| set_show(false)>
            "Cancel"
        </Button>
        <Button variant=ButtonVariant::Destructive>
            "Delete"
        </Button>
    </Dialog>
}

Installation

stratum add dialog

Props

PropTypeDefaultDescription
openOption<bool>NoneControlled open state
default_openboolfalseInitial state for uncontrolled usage
modalbooltrueWhether to trap focus and show backdrop
on_open_changeOption<Callback<bool>>NoneFires when open state changes

Accessibility

  • Renders with role="dialog" and aria-modal="true".
  • aria-labelledby points to the DialogTitle, aria-describedby to DialogDescription.
  • Escape closes the dialog.
  • Focus is trapped within the dialog. On close, focus returns to the trigger element.
  • Tab and Shift+Tab cycle through focusable children.

Source

Primitive: dialog.rs
Styled: dialog.rs