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

docs / components / inputs / input docs / components / inputs /

input

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

Enter one line or several (textarea).

Click, drag or double-click to select, Shift with the arrows to extend; Ctrl / ⌘ with A, C, X, V, Z to select all, copy, cut, paste and undo; input methods are supported, with the composition drawn underlined at the caret.

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

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

Usage

rust
use amenui::widgets::{input, textarea};

fn view() -> El<Msg> {
    input("i1", &TextEdit::new("林"), "名称", 280.0, 40, Msg::Edit)
}

Examples

Empty

rust
fn view() -> El<Msg> {
    input("i2", &TextEdit::default(), "搜索…", 280.0, 40, Msg::Edit)
}

Several lines

rust
fn view() -> El<Msg> {
    textarea("i3", &TextEdit::new("第一行\n第二行"), "备注", 280.0, 3, 400, Msg::Edit)
}

API

Functionsinput, textarea
Propskey, edit: &TextEdit (text, caret, selection, composition, undo), placeholder, width, (rows,) max characters, msg.
Filessrc/widgets/input.rs
Depends onbase
Response to frontsnudge (a control: pushed as one piece by fronts, held and condensing at most to Look::legible_cap)
Recompositionnever (typing is immediate)

Keyboard and accessibility

Statesempty with placeholder, focused with caret and selection, composing (underlined), disabled.
Keys and messagesmsg(TextEdit) with the edited value for every text event; typing never recomposes.

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

Recipes: A form