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

docs / components / inputs / number docs / components / inputs /

number

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

Set a value exactly: type it once focused, or step it with the arrow keys and the buttons on either side; drag across the value to scrub it.

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

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

Usage

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

fn view() -> El<Msg> {
    number("n1", "份数", 3.0, Spec { min: 0.0, max: 9.0, step: 1.0, decimals: 0, unit: "" }, None, Msg::Num).width(320.0)
}

Examples

With a unit

rust
fn view() -> El<Msg> {
    number("n2", "宽度", 12.5, Spec { min: 0.0, max: 64.0, step: 0.5, decimals: 1, unit: "px" }, None, Msg::Num).width(320.0)
}

API

Functionsnumber
Propskey, label, value, spec: Spec (min, max, step, decimals, unit), draft (what is being typed), msg.
Filessrc/widgets/number.rs
Depends onbase
Response to frontsnudge (a control: pushed as one piece by fronts, held and condensing at most to Look::legible_cap)
Recompositionits value text ({key}/shown) recomposes when the value changes

Keyboard and accessibility

Statesrest, focused, typing (ink border, accent caret), disabled; a new value recomposes its digits ({key}/shown).
Keys and messagesmsg(Edit::Draft(s)) while typing, Edit::Set(v) on Enter / steps / arrows / scrub, Edit::Cancel on Esc or blur.

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