amenui
en·中 github ↗ v0.0.1
01docs 02components 03lab 04works
en·中github ↗
×

docs / components / inputs / toggle docs / components / inputs /

toggle

04.10
On this page ▾
  1. Installation
  2. Usage
  3. Examples
  4. API
  5. Keyboard and accessibility

A button that stays pressed, or a group of them.

drawn by amenuiopen ↗

Installation

Components are distributed as source. Copy it and what it depends on into your project, then change it as you need:

sh
cargo run --release --bin amenui -- add toggle --to ../my-app

Files copied: src/widgets/toggle.rs, src/widgets/mod.rs

Usage

rust
use amenui::widgets::{toggle, toggle_group};

fn view() -> El<Msg> {
    toggle("tg1", "B", true, Msg::Nothing)
}

Examples

A group

rust
fn view() -> El<Msg> {
    toggle_group("tg2", &["左", "中", "右"], &[true, false, false], Msg::Pick)
}

API

Functionstoggle, toggle_group
Propstoggle: key, label, on, msg; toggle_group: key, labels, on (one per label), msg(i).
Filessrc/widgets/toggle.rs
Depends onbase
Response to frontsnudge (a control: pushed as one piece by fronts, held and condensing at most to Look::legible_cap)
Recompositionkeyed labels recompose when their text changes

Keyboard and accessibility

Statesoff, on (aria-pressed), focused; in a group one focus stop, Left / Right move focus by choosing, Space toggles.
Keys and messagesmsg / msg(i) on press, Enter or Space.

On the web every control is mirrored into the page as an element with its role and name, so screen readers and the browser's own focus see it (DESIGN.md §1.14).