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

docs / components / navigation / menu docs / components / navigation /

menu

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

A button that shows the current option; pressing it lists every option in a layer below it.

Press one to choose it; press outside the list or Esc to close.

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

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

Usage

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

fn view() -> El<Msg> {
    menu("m1", "主题", &["暗", "明", "纸"], Some(0), false, false, Msg::Nothing, Msg::Nothing, Msg::Pick)
}

API

Functionsmenu
Propskey, label, options, current, open, commit (the choice is a commit: theme, material), toggle, close, pick.
Filessrc/widgets/menu.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 current option) or open (a layer under the button).
Keys and messagestoggle on the button, pick(i) on an option, close outside or on Esc.

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