Accordion
A set of collapsible panels opened by their headers.
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.
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
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a AccordionRoot with its default configuration. |
.child | pub fn child(mut self, child: impl Into<AccordionRootChild<T>>) -> Self
Adds one typed child to this part. |
.children | pub fn children(mut self, children: impl IntoIterator<Item = impl Into<AccordionRootChild<T>>>,) -> Self
Adds multiple typed children in iteration order. |
.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_value | pub fn default_value(mut self, default_value: Vec<T>) -> Self
Sets the initial value for uncontrolled state. Later user changes are retained by the component. |
.value | pub fn value(mut self, value: Vec<T>) -> Self
Sets the current controlled value or the value represented by this part, depending on the part's role. |
.disabled | pub fn disabled(mut self, disabled: bool) -> Self
When true, prevents user interaction with this part. |
.multiple | pub fn multiple(mut self, multiple: bool) -> Self
Controls whether more than one value may be selected at the same time. |
.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. |
.orientation | pub fn orientation(mut self, orientation: AccordionOrientation) -> Self
Sets the component's horizontal or vertical orientation and corresponding keyboard behavior. |
.on_value_change | pub fn on_value_change(mut self, on_value_change: impl Fn(&[T], &mut AccordionValueChangeDetails, &mut Window, &mut App) + 'static,) -> Self
Registers a callback invoked when value change occurs. |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(AccordionRootStyleState<T>, Div) -> Div + 'static,) -> Self
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.
use base_gpui::accordion::AccordionTrigger;
AccordionTrigger::new()
.id("example-id")
.aria_label("aria label")
.style_with_state(|/* callback arguments */| { /* handle change */ });
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a AccordionTrigger 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. |
.aria_label | pub fn aria_label(mut self, aria_label: impl Into<SharedString>) -> Self
Accessible name for triggers whose visible content is iconic/non-textual. When set, render the visible label with |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(AccordionTriggerStyleState<T>, Div) -> Div + 'static,) -> Self
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.
use base_gpui::accordion::AccordionHeader;
AccordionHeader::new()
.id("example-id")
.heading_level(0)
.style_with_state(|/* callback arguments */| { /* handle change */ });
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a AccordionHeader 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. |
.heading_level | pub fn heading_level(mut self, heading_level: usize) -> Self
Sets the heading level configuration for this part. |
.child | pub fn child(mut self, child: impl Into<AccordionHeaderChild<T>>) -> Self
Adds one typed child to this part. |
.children | pub fn children(mut self, children: impl IntoIterator<Item = impl Into<AccordionHeaderChild<T>>>,) -> Self
Adds multiple typed children in iteration order. |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(AccordionHeaderStyleState<T>, Div) -> Div + 'static,) -> Self
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.
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
| Builder | Signature & description |
|---|---|
.new | pub fn new(value: T) -> Self
Creates a AccordionItem 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<AccordionItemChild<T>>) -> Self
Adds one typed child to this part. |
.children | pub fn children(mut self, children: impl IntoIterator<Item = impl Into<AccordionItemChild<T>>>,) -> 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. |
.on_open_change | pub fn on_open_change(mut self, on_open_change: impl Fn(bool, &mut AccordionItemOpenChangeDetails, &mut Window, &mut App) + 'static,) -> Self
Registers a callback invoked when open change occurs. |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(AccordionItemStyleState<T>, Div) -> Div + 'static,) -> Self
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.
use base_gpui::accordion::AccordionPanel;
AccordionPanel::new()
.id("example-id")
.keep_mounted(true)
.style_with_state(|/* callback arguments */| { /* handle change */ });
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a AccordionPanel 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. |
.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(AccordionPanelStyleState<T>, Div) -> Div + 'static,) -> Self
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.