Skip to content

Checkbox ​

The Checkbox widget displays a toggleable checked/unchecked/indeterminate state with an optional label.

Basic Usage ​

Create a checkbox with the Checkbox() extension method. Use OnToggled() to handle state changes.

csharp
using Hex1b;
using Hex1b.Widgets;

var state = new TermsState();

await using var terminal = Hex1bTerminal.CreateBuilder()
    .WithHex1bApp((app, options) => ctx => ctx.VStack(v => [
        v.Text("Terms and Conditions"),
        v.Text(""),
        v.Checkbox(state.AcceptTerms ? CheckboxValue.Checked : CheckboxValue.Unchecked)
            .Label("I accept the terms")
            .OnToggled(e => state.AcceptTerms = !state.AcceptTerms),
        v.Text(""),
        v.Button("Continue")
            .OnClick(_ => { if (state.AcceptTerms) Console.WriteLine("Accepted!"); })
    ]))
    .Build();

await terminal.RunAsync();

class TermsState
{
    public bool AcceptTerms { get; set; }
}

Key features:

  • Click or press Space/Enter to toggle
  • Use Label() to add descriptive text
  • Manage state externally (checkboxes are stateless widgets)

States ​

Checkboxes support three visual states:

csharp
using Hex1b;
using Hex1b.Widgets;

await using var terminal = Hex1bTerminal.CreateBuilder()
    .WithHex1bApp((app, options) => ctx => ctx.VStack(v => [
        v.Text("Checkbox States:"),
        v.Text(""),
        v.Checkbox().Unchecked().Label("Unchecked ▢"),
        v.Checkbox().Checked().Label("Checked ▣"),
        v.Checkbox().Indeterminate().Label("Indeterminate ▤")
    ]))
    .Build();

await terminal.RunAsync();
StateDisplayUsage
Unchecked▢Default, option not selected
Checked▣Option is selected
Indeterminate▤Partial selection (e.g., some children selected)

Fluent API ​

MethodDescription
Checked()Set to checked state
Unchecked()Set to unchecked state
Indeterminate()Set to indeterminate state
Label(string)Add label text after the checkbox
OnToggled(handler)Handle toggle events

Keyboard Support ​

KeyAction
SpaceToggle the checkbox
EnterToggle the checkbox
TabMove to next focusable widget
  • ToggleSwitch — On/off switch with visual feedback
  • Tree — Hierarchical lists with multi-select checkboxes
  • Button — Clickable actions

Released under the MIT License.