Checkbox
A control that allows the user to toggle between checked and not checked.
Features
- Supports indeterminate state.
- Full keyboard navigation.
- Can be controlled or uncontrolled.
Installation
Install the component from your command line.
cargo add radix-leptos-checkbox
Anatomy
Import all parts and piece them together.
use leptos::*;
use radix_leptos_checkbox::*;
#[component]
fn Anatomy() -> impl IntoView {
view! {
<Checkbox>
<CheckboxIndicator />
</Checkbox>
}
}
API Reference
Root
Contains all the parts of a checkbox. An input
will also render when used within a form
to ensure events propagate correctly.
Prop | Type | Default |
---|---|---|
as_child | MaybeProp<bool> | false |
default_checked | MaybeProp<CheckedState> | - |
checked | MaybeProp<CheckedState> | - |
on_checked_change | Option<Callback<bool>> | - |
disabled | MaybeProp<bool> | - |
required | MaybeProp<bool> | - |
name | MaybeProp<String> | - |
value | MaybeProp<String> | "on" |
Data attribute | Values |
---|---|
[data-state] | "checked" | "unchecked" | "indeterminate" |
[data-disabled] | Present when disabled |
Indicator
Renders when the checkbox is in a checked or indeterminate state. You can style this element directly, or you can use it as a wrapper to put an icon into, or both.
Prop | Type | Default |
---|---|---|
as_child | MaybeProp<bool> | false |
force_mount | MaybeProp<bool> | - |
Data attribute | Values |
---|---|
[data-state] | "checked" | "unchecked" | "indeterminate" |
[data-disabled] | Present when disabled |
Examples
Indeterminate
You can set the checkbox to CheckedState::Indeterminate
by taking control of its state.
TODO
Accessibility
Adheres to the tri-state Checkbox WAI-ARIA design pattern.
Keyboard Interactions
Key | Description |
---|---|
Space | Checks/unchecks the checkbox. |