Toolbar
Groups buttons and inputs behind a single tab stop.
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 toolbar
The demo failed to start in this browser.
You can run it natively instead: cargo run -p showcase toolbar
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::toolbar::{
ToolbarButton,
ToolbarGroup,
ToolbarInput,
ToolbarLink,
ToolbarRoot,
ToolbarSeparator,
};
ToolbarRoot::new()
.child(
ToolbarGroup::new()
.child(
ToolbarButton::new(),
)
.child(
ToolbarInput::new(),
)
.child(
ToolbarLink::new(),
),
)
.child(
ToolbarSeparator::new(),
);
The anatomy is a structural overview. Parts with mutually exclusive modes may need separate instances; each part's section below documents its configuration.
#ToolbarRoot
Coordinates the component's state and supplies context to its child parts.
use base_gpui::toolbar::ToolbarRoot;
ToolbarRoot::new()
.id("example-id")
.orientation(/* orientation: ToolbarOrientation */)
.loop_focus(true)
.disabled(true)
.aria_label("aria label")
.style_with_state(|/* callback arguments */| { /* handle change */ });
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a ToolbarRoot 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<ToolbarChild>) -> Self
Adds one typed child to this part. |
.children | pub fn children(mut self, children: impl IntoIterator<Item = impl Into<ToolbarChild>>) -> Self
Adds multiple typed children in iteration order. |
.orientation | pub fn orientation(mut self, orientation: ToolbarOrientation) -> Self
Sets the component's horizontal or vertical orientation and corresponding keyboard behavior. |
.loop_focus | pub fn loop_focus(mut self, loop_focus: bool) -> Self
Controls whether keyboard focus wraps from the last enabled item to the first and vice versa. |
.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, aria_label: impl Into<SharedString>) -> Self
Accessible name for the toolbar, announced by screen readers. There is no |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(ToolbarRootStyleState, Div) -> Div + 'static,) -> Self
Styles the part from its current behavioral state while preserving separation between behavior and visual design. ToolbarRoot also supports the GPUI traits implemented in its source, such as standard styling or child composition. |
#ToolbarButton
Public renderable part of the Toolbar Button component.
use base_gpui::toolbar::ToolbarButton;
ToolbarButton::new()
.id("example-id")
.disabled(true)
.focusable_when_disabled(true)
.aria_label("aria label")
.on_click(|/* callback arguments */| { /* handle change */ })
.style_with_state(|/* callback arguments */| { /* handle change */ })
.own_disabled()
.own_focusable_when_disabled()
.item_id()
.with_toolbar(/* context: ToolbarContext */, 0, /* focus_handle: FocusHandle */, true);
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a ToolbarButton 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. |
.focusable_when_disabled | pub fn focusable_when_disabled(mut self, focusable_when_disabled: bool) -> Self
Sets the focusable when disabled configuration for this part. |
.aria_label | pub fn aria_label(mut self, aria_label: impl Into<SharedString>) -> Self
Accessible name for icon-only buttons. When set alongside a visible text child, render that text with |
.on_click | pub fn on_click(mut self, on_click: impl Fn(&ClickEvent, &mut Window, &mut App) + 'static,) -> Self
Registers a callback invoked when click occurs. |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(ToolbarButtonStyleState, Div) -> Div + 'static,) -> Self
Styles the part from its current behavioral state while preserving separation between behavior and visual design. |
.own_disabled | pub fn own_disabled(&self) -> boolThe button's own disabled prop, consumed by the toolbar child wiring when resolving the effective per-item disabled fact. |
.own_focusable_when_disabled | pub fn own_focusable_when_disabled(&self) -> boolThe button's |
.item_id | pub fn item_id(&self) -> &ElementIdThe button's element id, consumed by the toolbar child wiring to key the roving focus handle. |
.with_toolbar | pub fn with_toolbar(mut self, context: ToolbarContext, index: usize, focus_handle: FocusHandle, cascade_disabled: bool,) -> Self
Attaches this button to a toolbar as a composite item. Called by the toolbar child wiring; not intended for direct use. ToolbarButton also supports the GPUI traits implemented in its source, such as standard styling or child composition. |
#ToolbarGroup
Groups related child parts and coordinates their shared behavior.
use base_gpui::toolbar::ToolbarGroup;
ToolbarGroup::new()
.id("example-id")
.disabled(true)
.aria_label("aria label")
.style_with_state(|/* callback arguments */| { /* handle change */ })
.own_disabled()
.split_children()
.with_toolbar(/* context: ToolbarContext */, true, /* children */);
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a ToolbarGroup with its default configuration. |
.id | pub fn id(mut self, id: impl Into<ElementId>) -> Self
Overrides the default |
.child | pub fn child(mut self, child: impl Into<ToolbarGroupChild>) -> Self
Adds one typed child to this part. |
.children | pub fn children(mut self, children: impl IntoIterator<Item = impl Into<ToolbarGroupChild>>,) -> Self
Adds multiple typed children in iteration order. |
.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, aria_label: impl Into<SharedString>) -> Self
Accessible name for the group, announced by screen readers. There is no |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(ToolbarGroupStyleState, Div) -> Div + 'static,) -> Self
Styles the part from its current behavioral state while preserving separation between behavior and visual design. |
.own_disabled | pub fn own_disabled(&self) -> boolThe group's own disabled prop, consumed by the toolbar child wiring when computing the merged cascade for contained items. |
.split_children | pub fn split_children(mut self) -> (Self, Vec<ToolbarGroupChild>)Detaches the typed children so the toolbar child wiring can flatten them into the toolbar's single item order. Called by the toolbar child wiring; not intended for direct use. |
.with_toolbar | pub fn with_toolbar(mut self, context: ToolbarContext, merged_disabled: bool, children: Vec<ToolbarGroupChild>,) -> Self
Reattaches the wired children and the toolbar context. Called by the toolbar child wiring; not intended for direct use. ToolbarGroup also supports the GPUI traits implemented in its source, such as standard styling or child composition. |
#ToolbarInput
Text input integrated with the component's state and behavior.
use base_gpui::toolbar::ToolbarInput;
ToolbarInput::new()
.id("example-id")
.value(/* value: impl Into<SharedString> */)
.default_value(/* default_value: impl Into<SharedString> */)
.placeholder("placeholder")
.on_value_change(|/* callback arguments */| { /* handle change */ })
.on_enter(|/* callback arguments */| { /* handle change */ })
.disabled(true)
.focusable_when_disabled(true)
.style_with_state(|/* callback arguments */| { /* handle change */ })
.own_disabled()
.own_focusable_when_disabled()
.item_id()
.with_toolbar(/* context: ToolbarContext */, 0, /* focus_handle: FocusHandle */, true);
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a ToolbarInput 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. |
.value | pub fn value(mut self, value: impl Into<SharedString>) -> Self
Sets the current controlled value or the value represented by this part, depending on the part's role. |
.default_value | pub fn default_value(mut self, default_value: impl Into<SharedString>) -> Self
Sets the initial value for uncontrolled state. Later user changes are retained by the component. |
.placeholder | pub fn placeholder(mut self, placeholder: impl Into<SharedString>) -> Self
Sets the content shown when the component has no current value. |
.on_value_change | pub fn on_value_change(mut self, on_value_change: impl Fn(SharedString) + 'static) -> Self
Registers a callback invoked when value change occurs. |
.on_enter | pub fn on_enter(mut self, on_enter: impl Fn(SharedString) + 'static) -> Self
Registers a callback invoked when enter occurs. |
.disabled | pub fn disabled(mut self, disabled: bool) -> Self
When true, prevents user interaction with this part. |
.focusable_when_disabled | pub fn focusable_when_disabled(mut self, focusable_when_disabled: bool) -> Self
Sets the focusable when disabled configuration for this part. |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(ToolbarInputStyleState, Div) -> Div + 'static,) -> Self
Styles the part from its current behavioral state while preserving separation between behavior and visual design. |
.own_disabled | pub fn own_disabled(&self) -> boolThe input's own disabled prop, consumed by the toolbar child wiring when resolving the effective per-item disabled fact. |
.own_focusable_when_disabled | pub fn own_focusable_when_disabled(&self) -> boolThe input's |
.item_id | pub fn item_id(&self) -> &ElementIdThe input's element id, consumed by the toolbar child wiring to key the roving focus handle. |
.with_toolbar | pub fn with_toolbar(mut self, context: ToolbarContext, index: usize, focus_handle: FocusHandle, cascade_disabled: bool,) -> Self
Attaches this input to a toolbar as a composite item. Called by the toolbar child wiring; not intended for direct use. ToolbarInput also supports the GPUI traits implemented in its source, such as standard styling or child composition. |
#ToolbarLink
Public renderable part of the Toolbar Link component.
use base_gpui::toolbar::ToolbarLink;
ToolbarLink::new()
.id("example-id")
.on_click(|/* callback arguments */| { /* handle change */ })
.aria_label("aria label")
.style_with_state(|/* callback arguments */| { /* handle change */ })
.item_id()
.with_toolbar(/* context: ToolbarContext */, 0, /* focus_handle: FocusHandle */);
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a ToolbarLink 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. |
.on_click | pub fn on_click(mut self, on_click: impl Fn(&ClickEvent, &mut Window, &mut App) + 'static,) -> Self
Registers a callback invoked when click occurs. |
.aria_label | pub fn aria_label(mut self, aria_label: impl Into<SharedString>) -> Self
Accessible name for icon-only links. When set alongside a visible text child, render that text with |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(ToolbarLinkStyleState, Div) -> Div + 'static,) -> Self
Styles the part from its current behavioral state while preserving separation between behavior and visual design. |
.item_id | pub fn item_id(&self) -> &ElementIdThe link's element id, consumed by the toolbar child wiring to key the roving focus handle. |
.with_toolbar | pub fn with_toolbar(mut self, context: ToolbarContext, index: usize, focus_handle: FocusHandle,) -> Self
Attaches this link to a toolbar as a composite item. Called by the toolbar child wiring; not intended for direct use. ToolbarLink also supports the GPUI traits implemented in its source, such as standard styling or child composition. |
#ToolbarSeparator
Visual separator between neighboring items or groups.
use base_gpui::toolbar::ToolbarSeparator;
ToolbarSeparator::new()
.orientation(/* orientation: SeparatorOrientation */)
.style_with_state(|/* callback arguments */| { /* handle change */ })
.with_toolbar(/* context: ToolbarContext */);
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a ToolbarSeparator with its default configuration. |
.orientation | pub fn orientation(mut self, orientation: SeparatorOrientation) -> Self
Overrides the derived perpendicular orientation. |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(SeparatorStyleState, Div) -> Div + 'static,) -> Self
Styles the part from its current behavioral state while preserving separation between behavior and visual design. |
.with_toolbar | pub fn with_toolbar(mut self, context: ToolbarContext) -> Self
Attaches the toolbar context so the default orientation can be derived. Called by the toolbar child wiring; not intended for direct use. ToolbarSeparator 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.