Expand description
Modal dialogs — a trigger button that presents a centered modal panel.
Three cooperating types cover the common dialog use-case. Dialog is the
high-level entry point: a Button (or custom trigger) that, on activation,
presents a ModalContainer above a full-viewport dimming ModalScrim.
DialogContent is the convenience body layout — a VStack with an
optional title, supporting text, scrollable body slot, and a footer slot
separated by a Divider.
§When to use
Dialog::new(label).content(|| …)for the common “button opens dialog” pattern.Dialog::new(label).trigger(my_icon_button).content(|| …)to use a custom widget as the trigger instead of the defaultButton.ModalContainer::new(content)directly when you need to present a modal from handler code viactx.present_modal(ModalRequest::…)rather than a persistent trigger.
§Accessibility
ModalContainer is a Role::Dialog node and announces set_modal().
Its accessible name defaults to the DialogContent title (via
Widget::accessible_title_hint) or falls back to the localized
a11y_dialog_name message; pass .title(tr!(…)) to the container for an
explicit override. When the content’s own node is already a dialog (a
MessageBox’s Role::AlertDialog, a CommandPalette’s Role::Dialog),
the container publishes no node of its own, so a reader meets one dialog
and hears its title once. The trigger button advertises HasPopup::Dialog and
set_expanded tracks whether the modal is currently open.
use teksilo_widgets::dialog::{Dialog, DialogContent};
use teksilo_i18n::lit;
let _d = Dialog::new(lit!("Open settings"))
.content(|| {
DialogContent::new()
.title(lit!("Settings"))
.supporting_text(lit!("Adjust your preferences below."))
});§Touch and pen
The trigger is a Button (or, with .trigger(..), the caller’s widget wrapped
in the same activation handlers), and both actuate on the release. The footer’s
buttons are buttons.
The scrim is the one full-viewport node that has to receive exactly the presses
that land on it, so it says no_hit_slop outright rather than relying on the
slop pass’s size formula to exclude it by arithmetic — see
scrim_hit_targeting_tests below. Its dismissal is a tap, so it too waits for
the release.
Structs§
- Dialog
- A trigger button that presents a modal dialog when activated.
- Dialog
Content - Convenience body layout for a modal dialog: optional title, supporting text,
scrollable body slot, and a
Divider-separated footer row. - Modal
Container - Rounded panel chrome that wraps a modal dialog’s content widget.
- Modal
Scrim - Full-viewport dimming scrim painted behind a
ModalContainer.