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

docs / components / layout / accordion docs / components / layout /

accordion

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

Sections that open and close under their headings.

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

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

Usage

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

fn view() -> El<Msg> {
    accordion("a1", vec![("什么是材质", text("第二遍的画法。", 13.0, Paint::TEXT)), ("什么是预设", text("一组数据。", 13.0, Paint::TEXT))], &[true, false], Msg::Pick).width(320.0)
}

API

Functionsaccordion
Propskey, items (title, body), open (which are open), msg.
Filessrc/widgets/accordion.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

Stateseach section open or closed; headings are buttons with aria-expanded.
Keys and messagesmsg(i) toggles section i (press, Enter, Space); Up / Down move between headings by Tab.

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