Dialog

A modal panel rendered on top of the page content.

EXAMPLEwasm · webgpu

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 dialog

The demo failed to start in this browser.

You can run it natively instead: cargo run -p showcase 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::dialog::{
    DialogBackdrop,
    DialogClose,
    DialogDescription,
    DialogPopup,
    DialogPortal,
    DialogRoot,
    DialogTitle,
    DialogTrigger,
    DialogViewport,
};

DialogRoot::new()
    .child(
        DialogPortal::new()
                .child(
                    DialogBackdrop::new(),
                )
                .child(
                    DialogViewport::new()
                                .child(
                                    DialogPopup::new()
                                                    .child(
                                                        DialogClose::new(),
                                                    )
                                                    .child(
                                                        DialogDescription::new(),
                                                    )
                                                    .child(
                                                        DialogTitle::new(),
                                                    ),
                                ),
                ),
    )
    .child(
        DialogTrigger::new(),
    );
The anatomy is a structural overview. Parts with mutually exclusive modes may need separate instances; each part's section below documents its configuration.

#DialogRoot

Coordinates the component's state and supplies context to its child parts.

Source

use base_gpui::dialog::DialogRoot;

DialogRoot::new()
    .id("example-id")
    .default_open(true)
    .open(true)
    .on_open_change(|/* callback arguments */| { /* handle change */ })
    .on_open_change_complete(|/* callback arguments */| { /* handle change */ })
    .modal(true)
    .modal_mode(/* modal_mode: DialogModalMode */)
    .trap_focus()
    .disable_pointer_dismissal(true)
    .trigger_id("example-id")
    .no_trigger_id()
    .default_trigger_id("example-id")
    .handle(/* handle: DialogHandle<P> */)
    .style_with_state(|/* callback arguments */| { /* handle change */ });

#Builders

BuilderSignature & description
.newpub fn new() -> Self

Creates a DialogRoot with its default configuration.

.childpub fn child(mut self, child: impl Into<DialogChild<P>>) -> Self
  • child: impl Into<DialogChild<P>>

Adds one typed child to this part.

.childrenpub fn children(mut self, children: impl IntoIterator<Item = impl Into<DialogChild<P>>>,) -> Self
  • children: impl IntoIterator<Item = impl Into<DialogChild<P>>>

Adds multiple typed children in iteration order.

.child_anypub fn child_any(mut self, child: impl IntoElement) -> Self
  • child: impl IntoElement

Adds one arbitrary renderable child to this part.

.idpub fn id(mut self, id: impl Into<ElementId>) -> Self
  • id: impl Into<ElementId>

Sets the stable GPUI element identity. Use a unique value when multiple instances can appear in the same view.

.default_openpub fn default_open(mut self, default_open: bool) -> Self
  • default_open: bool

Sets the initial open state for an uncontrolled component.

.openpub fn open(mut self, open: bool) -> Self
  • open: bool

Controls whether the component is open.

.on_open_changepub fn on_open_change(mut self, on_open_change: impl Fn(bool, &mut DialogOpenChangeDetails<P>, &mut Window, &mut App) + 'static,) -> Self
  • on_open_change: impl Fn(bool, &mut DialogOpenChangeDetails<P>, &mut Window, &mut App) + 'static

Registers a callback invoked when open change occurs.

.on_open_change_completepub fn on_open_change_complete(mut self, on_open_change_complete: impl Fn(bool, &DialogOpenChangeDetails<P>, &mut Window, &mut App) + 'static,) -> Self
  • on_open_change_complete: impl Fn(bool, &DialogOpenChangeDetails<P>, &mut Window, &mut App) + 'static

Registers a callback invoked when open change complete occurs.

.modalpub fn modal(mut self, modal: bool) -> Self
  • modal: bool

Controls whether the overlay behaves modally and blocks interaction outside it.

.modal_modepub fn modal_mode(mut self, modal_mode: DialogModalMode) -> Self
  • modal_mode: DialogModalMode

Sets the modal mode configuration for this part.

.trap_focuspub fn trap_focus(mut self) -> Self

Controls whether trap focus behavior is enabled.

.disable_pointer_dismissalpub fn disable_pointer_dismissal(mut self, disable_pointer_dismissal: bool) -> Self
  • disable_pointer_dismissal: bool

Controls whether disable pointer dismissal behavior is enabled.

.trigger_idpub fn trigger_id(mut self, trigger_id: impl Into<ElementId>) -> Self
  • trigger_id: impl Into<ElementId>

Sets the trigger id configuration for this part.

.no_trigger_idpub fn no_trigger_id(mut self) -> Self

Sets the no trigger id configuration for this part.

.default_trigger_idpub fn default_trigger_id(mut self, trigger_id: impl Into<ElementId>) -> Self
  • trigger_id: impl Into<ElementId>

Sets the initial trigger id for uncontrolled state.

.handlepub fn handle(mut self, handle: DialogHandle<P>) -> Self
  • handle: DialogHandle<P>

Sets the handle configuration for this part.

.style_with_statepub fn style_with_state(mut self, style: impl Fn(DialogRootStyleState<P>, Div) -> Div + 'static,) -> Self
  • style: impl Fn(DialogRootStyleState<P>, Div) -> Div + 'static,

Styles the part from its current behavioral state while preserving separation between behavior and visual design.

DialogRoot also supports the GPUI traits implemented in its source, such as standard styling or child composition.

#DialogTrigger

Interactive control that opens, closes, or activates the component.

Source

use base_gpui::dialog::DialogTrigger;

DialogTrigger::new()
    .id("example-id")
    .disabled(true)
    .payload(/* payload: P */)
    .handle(/* handle: DialogHandle<P> */)
    .aria_label("label")
    .style_with_state(|/* callback arguments */| { /* handle change */ });

#Builders

BuilderSignature & description
.newpub fn new() -> Self

Creates a DialogTrigger with its default configuration.

.idpub fn id(mut self, id: impl Into<ElementId>) -> Self
  • id: impl Into<ElementId>

Sets the stable GPUI element identity. Use a unique value when multiple instances can appear in the same view.

.disabledpub fn disabled(mut self, disabled: bool) -> Self
  • disabled: bool

When true, prevents user interaction with this part.

.payloadpub fn payload(mut self, payload: P) -> Self
  • payload: P

Sets the payload configuration for this part.

.handlepub fn handle(mut self, handle: DialogHandle<P>) -> Self
  • handle: DialogHandle<P>

Sets the handle configuration for this part.

.aria_labelpub fn aria_label(mut self, label: impl Into<SharedString>) -> Self
  • label: impl Into<SharedString>

Sets a literal accessible name for this part.

.style_with_statepub fn style_with_state(mut self, style: impl Fn(DialogTriggerStyleState<P>, Div) -> Div + 'static,) -> Self
  • style: impl Fn(DialogTriggerStyleState<P>, Div) -> Div + 'static,

Styles the part from its current behavioral state while preserving separation between behavior and visual design.

DialogTrigger also supports the GPUI traits implemented in its source, such as standard styling or child composition.

#DialogPortal

Hosts overlay content outside the normal child layout.

Source

use base_gpui::dialog::DialogPortal;

DialogPortal::new()
    .keep_mounted(true)
    .style_with_state(|/* callback arguments */| { /* handle change */ });

#Builders

BuilderSignature & description
.newpub fn new() -> Self

Creates a DialogPortal with its default configuration.

.childpub fn child(mut self, child: impl Into<DialogPortalChild<P>>) -> Self
  • child: impl Into<DialogPortalChild<P>>

Adds one typed child to this part.

.child_anypub fn child_any(mut self, child: impl IntoElement) -> Self
  • child: impl IntoElement

Adds one arbitrary renderable child to this part.

.keep_mountedpub fn keep_mounted(mut self, keep_mounted: bool) -> Self
  • keep_mounted: bool

Keeps the part mounted when inactive or closed so child state can be preserved.

.style_with_statepub fn style_with_state(mut self, style: impl Fn(DialogPortalStyleState, Div) -> Div + 'static,) -> Self
  • style: impl Fn(DialogPortalStyleState, Div) -> Div + 'static,

Styles the part from its current behavioral state while preserving separation between behavior and visual design.

DialogPortal also supports the GPUI traits implemented in its source, such as standard styling or child composition.

#DialogPopup

Contains the floating interactive content.

Source

use base_gpui::dialog::DialogPopup;

DialogPopup::new()
    .id("example-id")
    .keep_mounted(true)
    .role(/* role: Role */)
    .aria_label("label")
    .payload_content(|/* callback arguments */| { /* handle change */ })
    .style_with_state(|/* callback arguments */| { /* handle change */ });

#Builders

BuilderSignature & description
.newpub fn new() -> Self

Creates a DialogPopup with its default configuration.

.idpub fn id(mut self, id: impl Into<ElementId>) -> Self
  • id: impl Into<ElementId>

Sets the stable GPUI element identity. Use a unique value when multiple instances can appear in the same view.

.childpub fn child(mut self, child: impl Into<DialogPopupChild<P>>) -> Self
  • child: impl Into<DialogPopupChild<P>>

Adds one typed child to this part.

.child_anypub fn child_any(mut self, child: impl IntoElement) -> Self
  • child: impl IntoElement

Adds one arbitrary renderable child to this part.

.keep_mountedpub fn keep_mounted(mut self, keep_mounted: bool) -> Self
  • keep_mounted: bool

Keeps the part mounted when inactive or closed so child state can be preserved.

.rolepub fn role(mut self, role: Role) -> Self
  • role: Role

Overrides the popup's accessibility role. Defaults to [Role::Dialog]; Alert Dialog sets [Role::AlertDialog].

.aria_labelpub fn aria_label(mut self, label: impl Into<SharedString>) -> Self
  • label: impl Into<SharedString>

Accessible name for the dialog. gpui has no aria-labelledby id-reference builder, so consumers pass the title string directly.

.payload_contentpub fn payload_content(mut self, content: impl Fn(Option<&P>, &mut Window, &mut App) -> AnyElement + 'static,) -> Self
  • content: impl Fn(Option<&P>, &mut Window, &mut App) -> AnyElement + 'static,

Sets the payload content configuration for this part.

.style_with_statepub fn style_with_state(mut self, style: impl Fn(DialogPopupStyleState<P>, Div) -> Div + 'static,) -> Self
  • style: impl Fn(DialogPopupStyleState<P>, Div) -> Div + 'static,

Styles the part from its current behavioral state while preserving separation between behavior and visual design.

DialogPopup also supports the GPUI traits implemented in its source, such as standard styling or child composition.

#DialogBackdrop

Covers content behind a modal overlay and handles outside interaction.

Source

use base_gpui::dialog::DialogBackdrop;

DialogBackdrop::new()
    .keep_mounted(true)
    .force_render(true)
    .force_rendered(true)
    .style_with_state(|/* callback arguments */| { /* handle change */ });

#Builders

BuilderSignature & description
.newpub fn new() -> Self

Creates a DialogBackdrop with its default configuration.

.keep_mountedpub fn keep_mounted(mut self, keep_mounted: bool) -> Self
  • keep_mounted: bool

Keeps the part mounted when inactive or closed so child state can be preserved.

.force_renderpub fn force_render(mut self, force_render: bool) -> Self
  • force_render: bool

Controls whether force render behavior is enabled.

.force_renderedpub fn force_rendered(self, force_rendered: bool) -> Self
  • force_rendered: bool

Controls whether force rendered behavior is enabled.

.style_with_statepub fn style_with_state(mut self, style: impl Fn(DialogBackdropStyleState, Div) -> Div + 'static,) -> Self
  • style: impl Fn(DialogBackdropStyleState, Div) -> Div + 'static,

Styles the part from its current behavioral state while preserving separation between behavior and visual design.

DialogBackdrop also supports the GPUI traits implemented in its source, such as standard styling or child composition.

#DialogClose

Interactive control that closes the component.

Source

use base_gpui::dialog::DialogClose;

DialogClose::new()
    .id("example-id")
    .disabled(true)
    .aria_label("label")
    .style_with_state(|/* callback arguments */| { /* handle change */ });

#Builders

BuilderSignature & description
.newpub fn new() -> Self

Creates a DialogClose with its default configuration.

.idpub fn id(mut self, id: impl Into<ElementId>) -> Self
  • id: impl Into<ElementId>

Sets the stable GPUI element identity. Use a unique value when multiple instances can appear in the same view.

.disabledpub fn disabled(mut self, disabled: bool) -> Self
  • disabled: bool

When true, prevents user interaction with this part.

.aria_labelpub fn aria_label(mut self, label: impl Into<SharedString>) -> Self
  • label: impl Into<SharedString>

Accessible name for the close button (typically icon-only, e.g. "Close").

.style_with_statepub fn style_with_state(mut self, style: impl Fn(DialogCloseStyleState, Div) -> Div + 'static,) -> Self
  • style: impl Fn(DialogCloseStyleState, Div) -> Div + 'static,

Styles the part from its current behavioral state while preserving separation between behavior and visual design.

DialogClose also supports the GPUI traits implemented in its source, such as standard styling or child composition.

#DialogDescription

Provides supporting descriptive content.

Source

use base_gpui::dialog::DialogDescription;

DialogDescription::new()
    .id("example-id")
    .style_with_state(|/* callback arguments */| { /* handle change */ });

#Builders

BuilderSignature & description
.newpub fn new() -> Self

Creates a DialogDescription with its default configuration.

.idpub fn id(mut self, id: impl Into<ElementId>) -> Self
  • id: impl Into<ElementId>

Sets the stable GPUI element identity. Use a unique value when multiple instances can appear in the same view.

.style_with_statepub fn style_with_state(mut self, style: impl Fn(DialogDescriptionStyleState<P>, Div) -> Div + 'static,) -> Self
  • style: impl Fn(DialogDescriptionStyleState<P>, Div) -> Div + 'static,

Styles the part from its current behavioral state while preserving separation between behavior and visual design.

DialogDescription also supports the GPUI traits implemented in its source, such as standard styling or child composition.

#DialogTitle

Provides the component's visible title.

Source

use base_gpui::dialog::DialogTitle;

DialogTitle::new()
    .id("example-id")
    .style_with_state(|/* callback arguments */| { /* handle change */ });

#Builders

BuilderSignature & description
.newpub fn new() -> Self

Creates a DialogTitle with its default configuration.

.idpub fn id(mut self, id: impl Into<ElementId>) -> Self
  • id: impl Into<ElementId>

Sets the stable GPUI element identity. Use a unique value when multiple instances can appear in the same view.

.style_with_statepub fn style_with_state(mut self, style: impl Fn(DialogTitleStyleState<P>, Div) -> Div + 'static,) -> Self
  • style: impl Fn(DialogTitleStyleState<P>, Div) -> Div + 'static,

Styles the part from its current behavioral state while preserving separation between behavior and visual design.

DialogTitle also supports the GPUI traits implemented in its source, such as standard styling or child composition.

#DialogViewport

Defines the viewport used to lay out or constrain overlay content.

Source

use base_gpui::dialog::DialogViewport;

DialogViewport::new()
    .keep_mounted(true)
    .style_with_state(|/* callback arguments */| { /* handle change */ });

#Builders

BuilderSignature & description
.newpub fn new() -> Self

Creates a DialogViewport with its default configuration.

.childpub fn child(mut self, child: impl Into<DialogViewportChild<P>>) -> Self
  • child: impl Into<DialogViewportChild<P>>

Adds one typed child to this part.

.child_anypub fn child_any(mut self, child: impl IntoElement) -> Self
  • child: impl IntoElement

Adds one arbitrary renderable child to this part.

.keep_mountedpub fn keep_mounted(mut self, keep_mounted: bool) -> Self
  • keep_mounted: bool

Keeps the part mounted when inactive or closed so child state can be preserved.

.style_with_statepub fn style_with_state(mut self, style: impl Fn(DialogViewportStyleState<P>, Div) -> Div + 'static,) -> Self
  • style: impl Fn(DialogViewportStyleState<P>, Div) -> Div + 'static,

Styles the part from its current behavioral state while preserving separation between behavior and visual design.

DialogViewport 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.