Fieldset

Groups related fields under a shared legend.

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 fieldset

The demo failed to start in this browser.

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

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::fieldset::{
    FieldsetLegend,
    FieldsetRoot,
};

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

#FieldsetRoot

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

Source

use base_gpui::fieldset::FieldsetRoot;

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

#Builders

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

Creates a FieldsetRoot with its default configuration.

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

Adds one typed child to this part.

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

Adds multiple typed children in iteration order.

.child_anypub fn child_any(mut self, child: impl IntoElement) -> Self
  • child: impl IntoElement

Adds one arbitrary renderable child to this part.

.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, label: impl Into<SharedString>) -> Self
  • label: impl Into<SharedString>

Accessible label for the group, announced by screen readers. Substitutes for Base UI's aria-labelledby -> legend-id wiring, which gpui cannot express: pass the legend's text here and keep it in sync manually. When set, build the visible FieldsetLegend text with Text::new_inaccessible(...) so it is not announced twice.

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

When true, prevents user interaction with this part.

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

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

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

#FieldsetLegend

Public renderable part of the Fieldset Legend component.

Source

use base_gpui::fieldset::FieldsetLegend;

FieldsetLegend::new()
    .with_fieldset_context(/* context: FieldsetContext */)
    .style_with_state(|/* callback arguments */| { /* handle change */ });

#Builders

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

Creates a legend for a Fieldset. AccessKit: like Base UI's plain-div legend, this element has no role and is deliberately kept out of the a11y tree. Expose the group's label via FieldsetRoot::aria_label(...) instead. When you do, render the legend's visible text with Text::new_inaccessible(...) (not text!(...)) so screen readers do not announce the label twice.

.with_fieldset_contextpub fn with_fieldset_context(mut self, context: FieldsetContext) -> Self
  • context: FieldsetContext

Sets the with fieldset context configuration for this part.

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

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

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