Checkbox
A real checkbox with a label and second line, an indeterminate state for Select all, an error, a card row and a check that draws itself.
oxyn add checkboxDioxus
rsx! {
Checkbox {
label: "Run tests after every edit",
description: "Slower, but catches breakage early",
value: "checked",
on_change: move |c: Check| run_tests.set(c),
}
}Rendered from Rust at build time · goes live when visible
When to use
- A real checkbox with a label and second line, an indeterminate state for Select all, an error, a card row and a check that draws itself.
When not to use
- Switch between two to six options: use Segmented Control instead.
- How much the agent may do without asking: use Permission selector instead.
- On or off for things that apply right away: use Switch instead.
Installation
Checkbox is free and MIT. The oxyn CLI copies its code, and the components it needs, into src/oxyn/ of your Dioxus or GPUI project, so it is yours to change.
Terminal
cargo install --git https://github.com/ismailqureshi72/Oxyn oxyn-cli
oxyn init
oxyn add checkboxRust
use crate::oxyn::{Checkbox, PRIMITIVES_CSS};Rather depend on the crate? cargo add oxyn-dioxus oxyn-core --git https://github.com/ismailqureshi72/Oxyn, then use oxyn_dioxus::{Checkbox, PRIMITIVES_CSS};
Usage
Dioxus · rust
rsx! {
Checkbox {
label: "Run tests after every edit",
description: "Slower, but catches breakage early",
value: "checked",
on_change: move |c: Check| run_tests.set(c),
}
}Examples
Plain
Label and second line.
Code
rsx! {
Checkbox {
label: "Run tests after every edit",
description: "Slower, but catches breakage early",
value: "checked",
on_change: move |c: Check| run_tests.set(c),
}
}Card
A whole card row.
Code
rsx! {
Checkbox {
label: "Run tests after every edit",
description: "Slower, but catches breakage early",
value: "checked",
variant: "card",
on_change: move |c: Check| run_tests.set(c),
}
}Todo
Strikes the label through when done (Oxyn plus).
Code
rsx! {
Checkbox {
label: "Write the migration",
value: "checked",
variant: "todo",
on_change: move |c: Check| run_tests.set(c),
}
}Bulk
An approve-all row over a list (Oxyn plus).
Code
rsx! {
Checkbox {
label: "Approve all 4 edits",
value: "indeterminate",
variant: "bulk",
on_change: move |c: Check| run_tests.set(c),
}
}Indeterminate
Some of them: Select all.
Code
rsx! {
Checkbox {
label: "Select all files",
value: "indeterminate",
on_change: move |c: Check| run_tests.set(c),
}
}Error
Required, with its error in place.
Code
rsx! {
Checkbox {
label: "I understand this deletes the branch",
error: "Tick this to continue",
on_change: move |c: Check| run_tests.set(c),
}
}API reference
Checkbox
| Prop | Type | Default | Description |
|---|---|---|---|
labelrequired | String | — | Label. |
description | Option<String> | Default::default() | Second line. |
value | String | "unchecked" | `unchecked` · `checked` · `indeterminate`. |
error | Option<String> | Default::default() | Error text (also marks it invalid). |
variant | String | "plain" | `plain` · `card` · `todo` (strike-through when checked) · `bulk` (approve-all row). |
aria_label | Option<String> | Default::default() | Accessible name when there is no visible label (falls back to "Checkbox"). |
name | Option<String> | Default::default() | Form field name. |
required | bool | Default::default() | Required. |
size | String | "md" | `sm` · `md` · `lg`. |
speed | f32 | 1.0 | Draw-time multiplier (1 = 240 ms). |
tri_state | bool | Default::default() | Cycle through indeterminate on click. |
disabled | bool | Default::default() | Disabled. |
on_change | EventHandler<Check> | — | Changed. |
Read from the Rust signature and doc comments.
Keyboard interactions
| Key | Action |
|---|---|
| Space | Toggle |
| Tab | Next control |
Accessibility
- role=checkbox with aria-checked (mixed when indeterminate).
- The error is linked with aria-describedby and sets aria-invalid.
Responsive behaviour
- The card variant fills its container.
- The label is part of the hit area.
Notes for AI
- Import
Checkboxfromoxyn_dioxusand includePRIMITIVES_CSSplus the token stylesheet once. - A GPUI version exists:
CheckboxElinoxyn_gpui. - Props to set first:
label. - Keep its states and timings as they ship; restyle it through the CSS variables rather than by hand.