Checkbox

A control that toggles between checked and unchecked.

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 checkbox

The demo failed to start in this browser.

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

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::checkbox::{
    CheckboxIndicator,
    CheckboxRoot,
};

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

#CheckboxRoot

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

Source

use base_gpui::checkbox::CheckboxRoot;

CheckboxRoot::new()
    .id("example-id")
    .name("name")
    .default_checked(true)
    .checked(None)
    .indeterminate(true)
    .value(/* value: impl Into<SharedString> */)
    .form(/* form: impl Into<SharedString> */)
    .parent(true)
    .unchecked_value(/* unchecked_value: impl Into<SharedString> */)
    .disabled(true)
    .read_only(true)
    .required(true)
    .on_checked_change(|/* callback arguments */| { /* handle change */ })
    .aria_label("aria label")
    .style_with_state(|/* callback arguments */| { /* handle change */ });

#Builders

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

Creates a CheckboxRoot with its default configuration.

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

Adds one typed child to this part.

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

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.

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

Sets the form field name used when serializing or submitting the value.

.default_checkedpub fn default_checked(mut self, default_checked: bool) -> Self
  • default_checked: bool

Sets the initial checked for uncontrolled state.

.checkedpub fn checked(mut self, checked: Option<bool>) -> Self
  • checked: Option<bool>

Sets the checked configuration for this part.

.indeterminatepub fn indeterminate(mut self, indeterminate: bool) -> Self
  • indeterminate: bool

Sets the indeterminate configuration for this part.

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

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

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

Sets the form configuration for this part.

.parentpub fn parent(mut self, parent: bool) -> Self
  • parent: bool

Sets the parent configuration for this part.

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

Sets the unchecked value configuration for this part.

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

When true, prevents user interaction with this part.

.read_onlypub fn read_only(mut self, read_only: bool) -> Self
  • read_only: bool

When true, allows presentation and focus behavior without permitting value changes.

.requiredpub fn required(mut self, required: bool) -> Self
  • required: bool

Marks the control as required for validation and accessibility state.

.on_checked_changepub fn on_checked_change(mut self, on_checked_change: impl Fn(bool, &mut crate::checkbox::CheckboxCheckedChangeDetails, &mut Window, &mut App) + 'static,) -> Self
  • on_checked_change: impl Fn(bool, &mut crate::checkbox::CheckboxCheckedChangeDetails, &mut Window, &mut App) + 'static

Registers a callback invoked when checked change occurs.

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

Sets a literal accessible name for this part.

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

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

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

#CheckboxIndicator

Visual representation of the component's current state or value.

Source

use base_gpui::checkbox::CheckboxIndicator;

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

#Builders

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

Creates a CheckboxIndicator 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(CheckboxIndicatorStyleState, Div) -> Div + 'static,) -> Self
  • style: impl Fn(CheckboxIndicatorStyleState, Div) -> Div + 'static,

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

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