Drawer
A dialog that slides in from the edge of the screen and can be swiped away.
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 drawer
The demo failed to start in this browser.
You can run it natively instead: cargo run -p showcase drawer
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::drawer::{
DrawerBackdrop,
DrawerContent,
DrawerIndent,
DrawerIndentBackground,
DrawerPopup,
DrawerPortal,
DrawerProvider,
DrawerRoot,
DrawerSwipeArea,
DrawerViewport,
};
DrawerRoot::new()
.child(
DrawerIndent::new(),
)
.child(
DrawerIndentBackground::new(),
)
.child(
DrawerPortal::new()
.child(
DrawerBackdrop::new(),
)
.child(
DrawerViewport::new()
.child(
DrawerPopup::new()
.child(
DrawerContent::new(),
),
),
),
)
.child(
DrawerSwipeArea::new(),
);
The anatomy is a structural overview. Parts with mutually exclusive modes may need separate instances; each part's section below documents its configuration.
#DrawerRoot
Coordinates the component's state and supplies context to its child parts.
use base_gpui::drawer::DrawerRoot;
DrawerRoot::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> */)
.swipe_direction(/* swipe_direction: DrawerSwipeDirection */)
.snap_points(/* snap_points: Vec<DrawerSnapPoint> */)
.snap_to_sequential_points(true)
.default_snap_point(None)
.snap_point(None)
.on_snap_point_change(|/* callback arguments */| { /* handle change */ })
.nested_in(/* reporter: DrawerNestedReporter */)
.style_with_state(|/* callback arguments */| { /* handle change */ });
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a DrawerRoot with its default configuration. |
.child | pub fn child(mut self, child: impl Into<DrawerChild<P>>) -> Self
Adds one typed child to this part. |
.children | pub fn children(mut self, children: impl IntoIterator<Item = impl Into<DrawerChild<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. |
.modal | pub fn modal(mut self, modal: bool) -> Self
Controls whether the overlay behaves modally and blocks interaction outside it. |
.modal_mode | pub fn modal_mode(mut self, modal_mode: DialogModalMode) -> Self
Sets the modal mode configuration for this part. |
.trap_focus | pub fn trap_focus(mut self) -> SelfControls whether trap focus behavior is enabled. |
.disable_pointer_dismissal | pub fn disable_pointer_dismissal(mut self, disable_pointer_dismissal: bool) -> Self
Controls whether disable pointer dismissal behavior is enabled. |
.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: DialogHandle<P>) -> Self
Sets the handle configuration for this part. |
.swipe_direction | pub fn swipe_direction(mut self, swipe_direction: DrawerSwipeDirection) -> Self
Sets the swipe direction configuration for this part. |
.snap_points | pub fn snap_points(mut self, snap_points: Vec<DrawerSnapPoint>) -> Self
Sets the snap points configuration for this part. |
.snap_to_sequential_points | pub fn snap_to_sequential_points(mut self, snap_to_sequential_points: bool) -> Self
Sets the snap to sequential points configuration for this part. |
.default_snap_point | pub fn default_snap_point(mut self, default_snap_point: Option<DrawerSnapPoint>) -> Self
Sets the initial snap point for uncontrolled state. |
.snap_point | pub fn snap_point(mut self, snap_point: Option<DrawerSnapPoint>) -> Self
Calling this builder marks the snap point controlled even when |
.on_snap_point_change | pub fn on_snap_point_change(mut self, on_snap_point_change: impl Fn(Option<DrawerSnapPoint>, &mut DrawerSnapPointChangeDetails, &mut Window, &mut App) + 'static,) -> Self
Registers a callback invoked when snap point change occurs. |
.nested_in | pub fn nested_in(mut self, reporter: DrawerNestedReporter) -> Self
Links this drawer as nested inside a parent drawer; obtain the reporter from the parent's |
.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. DrawerRoot also supports the GPUI traits implemented in its source, such as standard styling or child composition. |
#DrawerPortal
Hosts overlay content outside the normal child layout.
use base_gpui::drawer::DrawerPortal;
DrawerPortal::new()
.keep_mounted(true)
.style_with_state(|/* callback arguments */| { /* handle change */ });
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a DrawerPortal with its default configuration. |
.child | pub fn child(mut self, child: impl Into<DrawerPortalChild<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. |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(DialogPortalStyleState, Div) -> Div + 'static,) -> Self
Styles the part from its current behavioral state while preserving separation between behavior and visual design. DrawerPortal also supports the GPUI traits implemented in its source, such as standard styling or child composition. |
#DrawerPopup
Contains the floating interactive content.
use base_gpui::drawer::DrawerPopup;
DrawerPopup::new()
.id("example-id")
.keep_mounted(true)
.role(/* role: Role */)
.aria_label("label")
.style_with_state(|/* callback arguments */| { /* handle change */ });
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a DrawerPopup 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<DrawerPopupChild<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. |
.role | pub fn role(mut self, role: Role) -> Self
Overrides the popup's accessibility role. Defaults to [ |
.aria_label | pub fn aria_label(mut self, label: impl Into<SharedString>) -> Self
Sets the popup's accessible name. gpui has no |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(DrawerPopupStyleState<P>, Div) -> Div + 'static,) -> Self
Styles the part from its current behavioral state while preserving separation between behavior and visual design. DrawerPopup also supports the GPUI traits implemented in its source, such as standard styling or child composition. |
#DrawerBackdrop
Covers content behind a modal overlay and handles outside interaction.
use base_gpui::drawer::DrawerBackdrop;
DrawerBackdrop::new()
.keep_mounted(true)
.force_render(true)
.style_with_state(|/* callback arguments */| { /* handle change */ });
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a DrawerBackdrop with its default configuration. |
.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. |
.force_render | pub fn force_render(mut self, force_render: bool) -> Self
Renders a nested drawer's backdrop anyway (default |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(DrawerBackdropStyleState, Div) -> Div + 'static,) -> Self
Styles the part from its current behavioral state while preserving separation between behavior and visual design. DrawerBackdrop also supports the GPUI traits implemented in its source, such as standard styling or child composition. |
#DrawerContent
Contains the component's user-provided content.
use base_gpui::drawer::DrawerContent;
DrawerContent::new()
.style_with_state(|/* callback arguments */| { /* handle change */ });
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a DrawerContent with its default configuration. |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(DrawerContentStyleState, Div) -> Div + 'static,) -> Self
Styles the part from its current behavioral state while preserving separation between behavior and visual design. DrawerContent also supports the GPUI traits implemented in its source, such as standard styling or child composition. |
#DrawerIndent
Public renderable part of the Drawer Indent component.
use base_gpui::drawer::DrawerIndent;
DrawerIndent::new()
.style_with_state(|/* callback arguments */| { /* handle change */ });
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a DrawerIndent with its default configuration. |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(DrawerIndentStyleState, Div) -> Div + 'static,) -> Self
Styles the part from its current behavioral state while preserving separation between behavior and visual design. DrawerIndent also supports the GPUI traits implemented in its source, such as standard styling or child composition. |
#DrawerIndentBackground
Public renderable part of the Drawer Indent Background component.
use base_gpui::drawer::DrawerIndentBackground;
DrawerIndentBackground::new()
.style_with_state(|/* callback arguments */| { /* handle change */ });
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a DrawerIndentBackground with its default configuration. |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(DrawerIndentBackgroundStyleState, Div) -> Div + 'static,) -> Self
Styles the part from its current behavioral state while preserving separation between behavior and visual design. DrawerIndentBackground also supports the GPUI traits implemented in its source, such as standard styling or child composition. |
#DrawerProvider
Public renderable part of the Drawer Provider component.
use base_gpui::drawer::DrawerProvider;
DrawerProvider::new();
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a DrawerProvider with its default configuration. DrawerProvider also supports the GPUI traits implemented in its source, such as standard styling or child composition. |
#DrawerSwipeArea
Public renderable part of the Drawer Swipe Area component.
use base_gpui::drawer::DrawerSwipeArea;
DrawerSwipeArea::new()
.id("example-id")
.disabled(true)
.swipe_direction(/* swipe_direction: DrawerSwipeDirection */)
.style_with_state(|/* callback arguments */| { /* handle change */ });
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a DrawerSwipeArea 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. |
.swipe_direction | pub fn swipe_direction(mut self, swipe_direction: DrawerSwipeDirection) -> Self
Overrides the open direction (default: opposite of the root |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(DrawerSwipeAreaStyleState, Div) -> Div + 'static,) -> Self
Styles the part from its current behavioral state while preserving separation between behavior and visual design. DrawerSwipeArea also supports the GPUI traits implemented in its source, such as standard styling or child composition. |
#DrawerViewport
Defines the viewport used to lay out or constrain overlay content.
use base_gpui::drawer::DrawerViewport;
DrawerViewport::new()
.id("example-id")
.keep_mounted(true)
.style_with_state(|/* callback arguments */| { /* handle change */ });
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a DrawerViewport 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<DrawerViewportChild<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. |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(DrawerViewportStyleState<P>, Div) -> Div + 'static,) -> Self
Styles the part from its current behavioral state while preserving separation between behavior and visual design. DrawerViewport 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.