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

docs / components / inputs / checkbox docs / components / inputs /

checkbox

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

Choose whether one option applies.

Press, Space or Enter toggles.

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 checkbox --to ../my-app

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

Usage

rust
use amenui::widgets::{checkbox};

fn view() -> El<Msg> {
    checkbox("cb1", "同意条款", false, Msg::Nothing)
}

Examples

Checked

rust
fn view() -> El<Msg> {
    checkbox("cb2", "同意条款", true, Msg::Nothing)
}

Disabled

rust
fn view() -> El<Msg> {
    checkbox("cb3", "同意条款", true, Msg::Nothing).disabled(true)
}

API

Functionscheckbox
Propskey, label, checked, msg.
Filessrc/widgets/checkbox.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

Statesunchecked, checked, focused, disabled.
Keys and messagesmsg on press, Space or Enter (WAI-ARIA checkbox: Space toggles).

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).