Collapsible

A panel that a trigger expands and collapses.

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 collapsible

The demo failed to start in this browser.

You can run it natively instead: cargo run -p showcase collapsible

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::collapsible::{
    CollapsiblePanel,
    CollapsibleRoot,
    CollapsibleTrigger,
};

CollapsibleRoot::new()
    .child(
        CollapsiblePanel::new(),
    )
    .child(
        CollapsibleTrigger::new(),
    );
The anatomy is a structural overview. Parts with mutually exclusive modes may need separate instances; each part's section below documents its configuration.

#CollapsibleRoot

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

Source

use base_gpui::collapsible::CollapsibleRoot;

CollapsibleRoot::new()
    .id("example-id")
    .default_open(true)
    .open(None)
    .disabled(true)
    .on_open_change(|/* callback arguments */| { /* handle change */ })
    .style_with_state(|/* callback arguments */| { /* handle change */ });

#Builders

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

Creates a CollapsibleRoot with its default configuration.

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

Adds one typed child to this part.

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

Adds multiple typed children in iteration order.

.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: Option<bool>) -> Self
  • open: Option<bool>

Controls whether the component is open.

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

When true, prevents user interaction with this part.

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

Registers a callback invoked when open change occurs.

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

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

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

#CollapsibleTrigger

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

Source

use base_gpui::collapsible::CollapsibleTrigger;

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

#Builders

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

Creates a CollapsibleTrigger 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.

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

Sets the accessible label announced for this trigger. Required for icon-only triggers. When the trigger also has a visible text label child, pass that child as Text::new_inaccessible(...) so screen readers do not announce the label twice; without an aria_label, leave child text accessible (text!(...)) so it names the button.

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

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

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

#CollapsiblePanel

Contains content associated with the active item.

Source

use base_gpui::collapsible::CollapsiblePanel;

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

#Builders

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

Creates a CollapsiblePanel 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.

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

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

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