Accordion

A set of collapsible panels opened by their headers.

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 accordion

The demo failed to start in this browser.

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

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::accordion::{
    AccordionHeader,
    AccordionItem,
    AccordionPanel,
    AccordionRoot,
    AccordionTrigger,
};

AccordionRoot::new()
    .child(
        AccordionItem::new(/* value: T */)
                .child(
                    AccordionHeader::new()
                                .child(
                                    AccordionTrigger::new(),
                                ),
                )
                .child(
                    AccordionPanel::new(),
                ),
    );
The anatomy is a structural overview. Parts with mutually exclusive modes may need separate instances; each part's section below documents its configuration.

#AccordionRoot

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

Source

use base_gpui::accordion::AccordionRoot;

AccordionRoot::new()
    .id("example-id")
    .default_value(/* default_value: Vec<T> */)
    .value(/* value: Vec<T> */)
    .disabled(true)
    .multiple(true)
    .keep_mounted(true)
    .orientation(/* orientation: AccordionOrientation */)
    .on_value_change(|/* callback arguments */| { /* handle change */ })
    .style_with_state(|/* callback arguments */| { /* handle change */ });

#Builders

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

Creates a AccordionRoot with its default configuration.

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

Adds one typed child to this part.

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

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_valuepub fn default_value(mut self, default_value: Vec<T>) -> Self
  • default_value: Vec<T>

Sets the initial value for uncontrolled state. Later user changes are retained by the component.

.valuepub fn value(mut self, value: Vec<T>) -> Self
  • value: Vec<T>

Sets the current controlled value or the value represented by this part, depending on the part's role.

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

When true, prevents user interaction with this part.

.multiplepub fn multiple(mut self, multiple: bool) -> Self
  • multiple: bool

Controls whether more than one value may be selected at the same time.

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

.orientationpub fn orientation(mut self, orientation: AccordionOrientation) -> Self
  • orientation: AccordionOrientation

Sets the component's horizontal or vertical orientation and corresponding keyboard behavior.

.on_value_changepub fn on_value_change(mut self, on_value_change: impl Fn(&[T], &mut AccordionValueChangeDetails, &mut Window, &mut App) + 'static,) -> Self
  • on_value_change: impl Fn(&[T], &mut AccordionValueChangeDetails, &mut Window, &mut App) + 'static

Registers a callback invoked when value change occurs.

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

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

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

#AccordionTrigger

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

Source

use base_gpui::accordion::AccordionTrigger;

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

#Builders

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

Creates a AccordionTrigger 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>

Accessible name for triggers whose visible content is iconic/non-textual. When set, render the visible label with Text::new_inaccessible(...) so screen readers do not announce the name twice.

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

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

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

#AccordionHeader

Public renderable part of the Accordion Header component.

Source

use base_gpui::accordion::AccordionHeader;

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

#Builders

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

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

.heading_levelpub fn heading_level(mut self, heading_level: usize) -> Self
  • heading_level: usize

Sets the heading level configuration for this part.

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

Adds one typed child to this part.

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

Adds multiple typed children in iteration order.

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

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

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

#AccordionItem

Represents one interactive item in the component's collection.

Source

use base_gpui::accordion::AccordionItem;

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

#Builders

BuilderSignature & description
.newpub fn new(value: T) -> Self
  • value: T

Creates a AccordionItem 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<AccordionItemChild<T>>) -> Self
  • child: impl Into<AccordionItemChild<T>>

Adds one typed child to this part.

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

Adds multiple typed children in iteration order.

.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 AccordionItemOpenChangeDetails, &mut Window, &mut App) + 'static,) -> Self
  • on_open_change: impl Fn(bool, &mut AccordionItemOpenChangeDetails, &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(AccordionItemStyleState<T>, Div) -> Div + 'static,) -> Self
  • style: impl Fn(AccordionItemStyleState<T>, Div) -> Div + 'static,

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

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

#AccordionPanel

Contains content associated with the active item.

Source

use base_gpui::accordion::AccordionPanel;

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

#Builders

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

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

.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(AccordionPanelStyleState<T>, Div) -> Div + 'static,) -> Self
  • style: impl Fn(AccordionPanelStyleState<T>, Div) -> Div + 'static,

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

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