Alert Dialog
A dialog that interrupts the user and requires a response.
This demo runs the real GPUI component on WebGPU, which this browser does not expose.
Try Chrome or Edge 113+, or Safari 26+. In Firefox, enable dom.webgpu.enabled.
You can also run it natively: cargo run -p showcase alert-dialog
The demo failed to start in this browser.
You can run it natively instead: cargo run -p showcase alert-dialog
Live examples are not supported on most mobile browsers yet — open this page on a desktop or tablet to run the demo.
Recent phones with WebGPU may manage it (downloads ~18 MB):
#Anatomy
Import the component's parts and compose them under its root:
use base_gpui::alert_dialog::{
AlertDialogPopup,
AlertDialogRoot,
AlertDialogTrigger,
};
AlertDialogRoot::new()
.child(
AlertDialogPopup::new(),
)
.child(
AlertDialogTrigger::new(),
);
The anatomy is a structural overview. Parts with mutually exclusive modes may need separate instances; each part's section below documents its configuration.
#AlertDialogRoot
Coordinates the component's state and supplies context to its child parts.
use base_gpui::alert_dialog::AlertDialogRoot;
AlertDialogRoot::new()
.id("example-id")
.default_open(true)
.open(true)
.on_open_change(|/* callback arguments */| { /* handle change */ })
.on_open_change_complete(|/* callback arguments */| { /* handle change */ })
.trigger_id("example-id")
.no_trigger_id()
.default_trigger_id("example-id")
.handle(/* handle: AlertDialogHandle<P> */)
.style_with_state(|/* callback arguments */| { /* handle change */ });
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a AlertDialogRoot with its default configuration. |
.child | pub fn child(mut self, child: impl Into<DialogChild<P>>) -> Self
Adds one typed child to this part. |
.children | pub fn children(mut self, children: impl IntoIterator<Item = impl Into<DialogChild<P>>>,) -> Self
Adds multiple typed children in iteration order. |
.child_any | pub fn child_any(mut self, child: impl IntoElement) -> Self
Adds one arbitrary renderable child to this part. |
.id | pub fn id(mut self, id: impl Into<ElementId>) -> Self
Sets the stable GPUI element identity. Use a unique value when multiple instances can appear in the same view. |
.default_open | pub fn default_open(mut self, default_open: bool) -> Self
Sets the initial open state for an uncontrolled component. |
.open | pub fn open(mut self, open: bool) -> Self
Controls whether the component is open. |
.on_open_change | pub fn on_open_change(mut self, on_open_change: impl Fn(bool, &mut DialogOpenChangeDetails<P>, &mut Window, &mut App) + 'static,) -> Self
Registers a callback invoked when open change occurs. |
.on_open_change_complete | pub fn on_open_change_complete(mut self, on_open_change_complete: impl Fn(bool, &DialogOpenChangeDetails<P>, &mut Window, &mut App) + 'static,) -> Self
Registers a callback invoked when open change complete occurs. |
.trigger_id | pub fn trigger_id(mut self, trigger_id: impl Into<ElementId>) -> Self
Sets the trigger id configuration for this part. |
.no_trigger_id | pub fn no_trigger_id(mut self) -> SelfSets the no trigger id configuration for this part. |
.default_trigger_id | pub fn default_trigger_id(mut self, trigger_id: impl Into<ElementId>) -> Self
Sets the initial trigger id for uncontrolled state. |
.handle | pub fn handle(mut self, handle: AlertDialogHandle<P>) -> Self
Sets the handle configuration for this part. |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(DialogRootStyleState<P>, Div) -> Div + 'static,) -> Self
Styles the part from its current behavioral state while preserving separation between behavior and visual design. AlertDialogRoot also supports the GPUI traits implemented in its source, such as standard styling or child composition. |
#AlertDialogTrigger
Interactive control that opens, closes, or activates the component.
use base_gpui::alert_dialog::AlertDialogTrigger;
AlertDialogTrigger::new()
.id("example-id")
.disabled(true)
.aria_label("label")
.payload(/* payload: P */)
.handle(/* handle: AlertDialogHandle<P> */)
.style_with_state(|/* callback arguments */| { /* handle change */ });
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a AlertDialogTrigger with its default configuration. |
.id | pub fn id(mut self, id: impl Into<ElementId>) -> Self
Sets the stable GPUI element identity. Use a unique value when multiple instances can appear in the same view. |
.disabled | pub fn disabled(mut self, disabled: bool) -> Self
When true, prevents user interaction with this part. |
.aria_label | pub fn aria_label(mut self, label: impl Into<SharedString>) -> Self
Accessible name for the trigger, used when the visible child is an icon or other non-text content. Forwarded to the underlying Dialog trigger's |
.payload | pub fn payload(mut self, payload: P) -> Self
Sets the payload configuration for this part. |
.handle | pub fn handle(mut self, handle: AlertDialogHandle<P>) -> Self
Sets the handle configuration for this part. |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(DialogTriggerStyleState<P>, Div) -> Div + 'static,) -> Self
Styles the part from its current behavioral state while preserving separation between behavior and visual design. AlertDialogTrigger also supports the GPUI traits implemented in its source, such as standard styling or child composition. |
#AlertDialogPopup
Contains the floating interactive content.
use base_gpui::alert_dialog::AlertDialogPopup;
AlertDialogPopup::new()
.id("example-id")
.keep_mounted(true)
.aria_label("label")
.payload_content(|/* callback arguments */| { /* handle change */ })
.style_with_state(|/* callback arguments */| { /* handle change */ });
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a AlertDialogPopup with its default configuration. |
.id | pub fn id(mut self, id: impl Into<ElementId>) -> Self
Sets the stable GPUI element identity. Use a unique value when multiple instances can appear in the same view. |
.child | pub fn child(mut self, child: impl Into<DialogPopupChild<P>>) -> Self
Adds one typed child to this part. |
.child_any | pub fn child_any(mut self, child: impl IntoElement) -> Self
Adds one arbitrary renderable child to this part. |
.keep_mounted | pub fn keep_mounted(mut self, keep_mounted: bool) -> Self
Keeps the part mounted when inactive or closed so child state can be preserved. |
.aria_label | pub fn aria_label(mut self, label: impl Into<SharedString>) -> Self
Accessible name for the alert dialog. gpui has no |
.payload_content | pub fn payload_content(mut self, content: impl Fn(Option<&P>, &mut Window, &mut App) -> AnyElement + 'static,) -> Self
Sets the payload content configuration for this part. |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(DialogPopupStyleState<P>, Div) -> Div + 'static,) -> Self
Styles the part from its current behavioral state while preserving separation between behavior and visual design. AlertDialogPopup also supports the GPUI traits implemented in its source, such as standard styling or child composition. |
#Accessibility
Keyboard interaction and accessibility semantics are implemented by the component, independently of visual styling. Known limitations caused by missing GPUI accessibility primitives are documented in the module source and are not silently approximated.
#Stability
Base GPUI is pre-1.0. Builder names and state types may evolve as GPUI and this port mature.