Toggle
A two-state button that can be either on or off.
Features
- Full keyboard navigation.
- Can be controlled or uncontrolled.
Installation
Install the component from your command line.
cargo add radix-leptos-toggle
Anatomy
Import the component.
use leptos::*;
use radix_leptos_toggle::*;
#[component]
fn Anatomy() -> impl IntoView {
view! {
<Toggle />
}
}
API Reference
Root
The toggle.
Prop | Type | Default |
---|---|---|
as_child | MaybeProp<bool> | false |
default_pressed | MaybeProp<bool> | - |
pressed | MaybeProp<bool> | - |
on_pressed_change | Option<Callback<bool>> | - |
disabled | MaybeProp<bool> | - |
Data attribute | Values |
---|---|
[data-state] | "on" | "off" |
[data-disabled] | Present when disabled |
Accessibility
Keyboard Interactions
Key | Description |
---|---|
Space | Activates/deactivates the toggle. |
Enter | Activates/deactivates the toggle. |