NumberInput
HkNumberInput is the boxed numeric field: a native type="number" element with in-field prefix and suffix affixes, bounded by min / max and guarded by the shared HkNumberSteppers column on the right. Values are clamped onto the declared bounds and never snapped onto the step grid. Reach for it for quantities, counts, prices in whole units — anything a user nudges by one.
- For free-text entry that happens to look numeric, use HkInput.
- For a slider-style picker with a visible range, use the slider family instead.
- For a money field with a currency mask, wrap HkInput with a suffix and your own parser.
Import
;
use *; // NumberInput, NumberInputSize, NumberStepperDirection
use *; // rsx!, VNode
The Rust form is a plain function, NumberInput(NumberInputProps { … }). One naming difference: Vue calls the value modelValue (a required prop), the Rust mirror calls it value: f64 and defaults it to 0.0 so the props struct stays Default-constructible.
Bounds and step
min and max clamp every path — typing, the ± column and the native arrow keys — and each one also gates its end of the column: at max the up button greys out, at min the down button does. step is both the amount each press moves and the native step attribute.
Affixes and sizes
prefix and suffix render text inside the field, flex-centered on either side of the input; in Vue the #prefix / #suffix slots win over the text props. size — sm / md / lg — is shared with the stepper column so the field and its buttons stay one block.
The Rust mirror takes the same two affixes as text props plus the slot props prefix_slot / suffix_slot, which win in the same order.
States and bounds
A disabled field dims the box, the affixes and the whole stepper column at once, so nothing about it reads as pressable. A field held at a bound shows only one live half of the column.
API
Vue
Props
| Name | Type | Default | Required |
|---|---|---|---|
| modelValue | Number | 0 | — |
| min | Number | undefined | — |
| max | Number | undefined | — |
| step | Number | 1 | — |
| disabled | Boolean | false | — |
| placeholder | String | undefined | — |
| label | String | undefined | — |
| id | String | undefined | — |
| prefix | String | undefined | — |
| suffix | String | undefined | — |
| size | <code>String as PropType<"sm" | "md" | "lg"></code> | "md" | — |
Emits
| Event | Payload |
|---|---|
| update:modelValue | number |
Rust
Props — NumberInput
| Prop | Type | Default | Description |
|---|---|---|---|
| value | f64 | 0.0 | Controlled value (Vue: modelValue, default 0). |
| min | Option<f64> | None | Lower bound; also the decrement dead end (Vue default undefined). |
| max | Option<f64> | None | Upper bound; also the increment dead end (Vue default undefined). |
| step | f64 | 1.0 | Step size used by the ± column and the native step attribute. |
| disabled | bool | false | — |
| placeholder | Option<String> | None | Native placeholder; None renders no attribute. |
| label | Option<String> | None | Caption above the box (Vue: label); empty means "no caption". |
| prefix | Option<String> | None | In-field affix text before the input (Vue: prefix). |
| suffix | Option<String> | None | In-field affix text after the input (Vue: suffix). |
| prefix_slot | Option<Element> | None | Vue: the #prefix slot — wins over NumberInputProps::prefix. |
| suffix_slot | Option<Element> | None | Vue: the #suffix slot — wins over NumberInputProps::suffix. |
| size | NumberInputSize | NumberInputSize::Medium | Size step (hk-number-input-{size}), shared with the step column. |
| id | Option<String> | None | Element id; when present, the caption's for points at the field and the field carries the id (delta [D] — Vue leaves the caption unbound). |
| class | String | "" | Host class appended last (Vue attribute fallthrough). |
| style | String | "" | Host style attribute (Vue attribute fallthrough). |
| oninput | Option<EventHandler<f64>> | None | Vue's update:modelValue — live, per keystroke and per step. |
| onchange | Option<EventHandler<f64>> | None | Commit channel (delta [D]): the field's native change (blur / Enter) and every step click, with the same clamped value as oninput. |
Accessibility
- The field is a native <input type="number">: assistive technology announces it as a spin button, the arrow keys step it natively and the native spin buttons are hidden by the stylesheet. An empty payload reads as 0, matching JavaScript's Number("").
- The caption is bound: Vue generates the field id with useId() when id is omitted, and the Rust mirror emits for={id} and the field's own id when the host passes one. Pass label rather than a loose sibling text to keep the name attached.
- The two step buttons are real buttons owned by HkNumberSteppers, and they render greyed at a dead end instead of disappearing — a bound is visible before it is hit.
- In Rust the mirror splits Vue's single emit: oninput fires per accepted value, onchange only on a commit (blur, Enter, or a step press), both carrying the same clamped value.
Related components
- HkInput — the general text field, with a number variant that drops the stepper column.
- HkSearchInput — the bare search field.
- HkPhoneInput — the phone field with a dial-code chip.
- HkOtpInput — the one-time-code field.