Skip to content

Checkbox

Control a labeled boolean choice.

On this page

Available with egui, Masonry and GPUI through the same public component API. Platform input and accessibility coverage still have alpha limits.

Usage

Replace src/App.iru in a scaffolded project with this complete file, then run cargo run. Keep the scaffold's main.rs and build.rs; this file includes its state, handlers and scoped styles.

src/App.iru
<view>
    <Column class="example">
        <Checkbox label="Receive notifications" model:checked={enabled} disabled={locked} class="choice" />
        <Checkbox label="Disable the control above" model:checked={locked} />
        <Text text={setting_label} />
        <Button text="Reset" @click={reset} class="action" />
    </Column>
</view>
<rust>
use inrux::prelude::*;

let enabled: Signal<bool> = Signal::new(false);
let setting_label_enabled = enabled.clone();
let setting_label: Computed<&'static str> = Computed::new(move || {
    if setting_label_enabled.get() {
        "Setting: on"
    } else {
        "Setting: off"
    }
});

let locked: bool = false;

/// Restore the value and enabled state together.
fn reset(state: &mut State, _: &Context<State>) {
    state.enabled.set(false);
    state.locked = false;
}
</rust>
<style scoped>
.example {
    padding: 24px;
    gap: 16px;
}
.action {
    background: #b84200;
    color: white;
    padding: 12px;
    border-radius: 6px;
}
.action:hover {
    background: #913400;
}
.action:focus-visible {
    border-width: 2px;
    border-color: #262626;
}
.choice {
    accent-color: #b84200;
}
.choice::part(label) {
    font-size: 16px;
}
</style>

API Reference

Props

PropTypeDefaultDescription
labelString-like expressionRequiredVisible label describing the choice.
checkedboolRequired without model:checkedControlled checked value.
model:checkedretained field: bool or Signal<bool>Not setTwo-way checked binding; use instead of checked.
disabledboolfalseReject checked-value changes.

Common props

PropTypeDefaultDescription
idString-like expressionNot setStyle-selector identity; independent of retained mount identity.
classString-like expressionNot setWhitespace-separated stylesheet classes.
styleStyleNot setExplicit Rust style overrides for this node.
keyString-like expressionNot setRetained sibling identity; preserve it while reordering children.
widthSizeComponent styleExplicit width constraint; otherwise use the resolved style.
heightSizeComponent styleExplicit height constraint; otherwise use the resolved style.
paddingf32Component styleUniform padding in logical pixels; otherwise use the resolved style.
gapf32Component styleChild spacing in logical pixels; otherwise use the resolved style.

“Component style” means the attribute is omitted and the normal style cascade supplies the value. Application styles can override framework defaults.

Emits

EventPayloadDescription
@changeboolRequested checked value. Required without a model; a model listener runs after assignment.

Bind events with @event={handler}. Ordinary handlers receive &mut State and &Context<State>; controlled value handlers can also receive the listed payload. With model:value or model:checked, the setter runs before the optional model listener, which reads the updated state. Stateless children forward a typed Emit<T>.

Behavior

The owner stores the boolean value. An enabled pointer or Enter/Space action requests a change; a disabled checkbox rejects activation. Use one model or one controlled pair, not both.

Styling and limits

Style the control, indicator and label parts within their supported properties. Checked/unchecked and keyboard-focus styles observe the owning control. Appearance changes must preserve the hit target and focus feedback.

Read the detailed reference for validation and native integration details. The playgrounds include a working Checkbox specimen with its surrounding state and reset controls.

Inrux · Built with Nuxt Content, IPEX, and Akaza UI.