Expand description
Numeric input — text input with − / + spinner buttons.
shadcn doesn’t ship a dedicated component (web apps lean on
<input type="number"> and let the browser draw spinners); for a
renderer-agnostic UI kit we render the spinners explicitly so the
affordance is consistent across backends.
The app owns the value as a String (matching crate::widgets::text_input) so
mid-edit states like "1." aren’t clobbered by a parse-and-reformat
round-trip on every keystroke. Parse to a number with
s.parse::<f64>() (or i64, …) when you actually need the value.
use aetna_core::prelude::*;
struct Form {
count: String,
selection: Selection,
}
impl App for Form {
fn build(&self, _cx: &BuildCx) -> El {
let opts = NumericInputOpts::default()
.min(0.0)
.max(100.0)
.step(1.0);
numeric_input(&self.count, &self.selection, "count", opts)
}
fn on_event(&mut self, e: UiEvent) {
let opts = NumericInputOpts::default()
.min(0.0)
.max(100.0)
.step(1.0);
numeric_input::apply_event(
&mut self.count, &mut self.selection, "count", &opts, &e,
);
}
}§Routed keys
{key}:dec—Clickon the−button. Steps the value down.{key}:inc—Clickon the+button. Steps the value up.{key}:field— the innercrate::widgets::text_input; routed text edits / IME commits / pointer caret moves all flow through this key.
Spinner clicks parse the current value, add or subtract
opts.step, clamp to opts.min/opts.max if set, and write the
formatted result back. If the value can’t be parsed (empty or
garbage), the spinner treats it as min when set, otherwise as
0.0.
§Dogfood note
Composes only the public widget-kit surface: a row with two
ghost buttons and an inner text_input_with. An app crate
can fork this file to add a different spinner shape (stacked
arrows, wheel-on-scroll, named units) without touching library
internals.
Structs§
- Numeric
Input Opts - Configuration for
numeric_input/apply_event.
Functions§
- apply_
event - Fold a routed
UiEventinto the numeric input’s value, handling both spinner clicks and text edits. Returnstrueif the event belonged to this widget (regardless of whether the value changed). - numeric_
input - A numeric input field:
[−] [text_input] [+].