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

docs / components / inputs / select docs / components / inputs /

select

04.9
On this page ▾
  1. Installation
  2. Usage
  3. API
  4. Keyboard and accessibility

Choose one option from a list that opens on demand.

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

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

Usage

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

fn view() -> El<Msg> {
    select("se1", &["北京", "上海", "广州"], Some(0), false, 0, Msg::Nothing, Msg::Nothing, Msg::Pick, Msg::Pick)
}

API

Functionsselect
Propskey, options, current, open, active (the option the keyboard is on while open), toggle, close, pick, move_to (the keyboard moves the active option).
Filessrc/widgets/select.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

Statesclosed (shows the choice), open (a listbox in a layer below), an active option.
Keys and messagestoggle on press, Enter, Space or Down (closed); while open Up / Down / Home / End send move_to(i), Enter / Space pick(active), Esc or a press outside close (WAI-ARIA select-only combobox).

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