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.

PropTypeDefault
as_childMaybeProp<bool>false
default_pressedMaybeProp<bool>-
pressedMaybeProp<bool>-
on_pressed_changeOption<Callback<bool>>-
disabledMaybeProp<bool>-
Data attributeValues
[data-state]"on" | "off"
[data-disabled]Present when disabled

Accessibility

Keyboard Interactions

KeyDescription
SpaceActivates/deactivates the toggle.
EnterActivates/deactivates the toggle.

See Also