-
Notifications
You must be signed in to change notification settings - Fork 9
Component NumberInput
MeowLynxSea edited this page Feb 14, 2026
·
5 revisions
A numeric input with stepper buttons.
The text field is controlled by the numeric value (non-numeric characters are not retained).
use gpui::ElementId;
use yororen_ui::component::number_input;
let view = number_input()
.key(ElementId::from(("settings", "retries")))
.min(0.0)
.max(10.0)
.step(1.0)
.value(3.0)
.on_change(|value, _window, _cx| {
// value: f64
});- Numeric settings where step buttons are convenient
- Values with min/max bounds
Not a good fit:
- Free-form numeric typing with partial input (this component intentionally sanitizes input)
-
number_input(): constructor -
id(...) / key(...): stable identity -
value(f64): initial/controlled value -
min(f64)/max(f64): bounds -
step(f64): step amount (0 becomes 1) placeholder("...")disabled(bool)-
validate(|raw: &str| bool): custom validation function, returns true if valid -
on_change(|value, window, cx| ...): fired when value changes - Styling:
bg/border/focus_border/text_color/height
- The input is kept controlled: it always reflects the current numeric value.
- Typing sanitizes to valid
f64format (digits,.,-, scientific notation like1.5e-10). - Use
.validate(...)to add custom validation rules (e.g., disallow negative numbers). - The
-/+buttons applystepand clamp tomin/max.
- Step:
1.0(if you setstep(0.0), it is treated as1.0) - Placeholder:
"0"
- Prefer
NumberInputwhen you want bounded values; preferTextInputwhen you need permissive typing.
// Only allow integers (no decimal point)
number_input()
.validate(|s| !s.contains('.'))
// Disallow negative numbers
number_input()
.validate(|s| !s.starts_with('-'))
// Allow only positive integers
number_input()
.validate(|s| s.parse::<f64>().map(|n| n >= 0.0).unwrap_or(false))Yororen UI v0.3.0 · repository · Apache-2.0 · This wiki documents Yororen UI v0.3.0.
This wiki documents Yororen UI v0.3.0 — the headless-core, swappable-renderer build.