NumberInput
A numeric field with step buttons, clamping, and precision.
Usage
Range and Precision
min / max set the range, step the increment, and precision the decimal places.
Loading demo...
Best Practices
- Pass explicit
min,max, andstepfor percentages, quotas, and pagination. - Handle decimals with
precisioninstead of rounding in the consumer after every event. - Set
controls=falsein dense table filters, where typing is faster. - Treat
nullas unset in validation and API mapping.
Edge and States
The steppers sit inside the same inset ring with concentric outer corners, and state colours match the input.
Loading demo...
API Reference
Props
| Prop | Type | Default | Description |
|---|---|---|---|
modelValue | number | null | null | The number; null when the field is empty, bound with v-model. |
min | number | - | Minimum value. |
max | number | - | Maximum value. |
step | number | 1 | Increment of the step buttons and the native input. |
precision | number | - | Decimal places to keep. |
placeholder | string | '' | Placeholder text. |
disabled | boolean | false | Disables the field and the buttons. |
readonly | boolean | false | Makes the field read-only and blocks stepping. |
controls | boolean | true | Shows the decrease and increase buttons. |
decreaseLabel | string | 'Decrease value' | The decrease button's aria-label; pass a localized string. |
increaseLabel | string | 'Increase value' | The increase button's aria-label; pass a localized string. |
Events
| Event | Params | Description |
|---|---|---|
update:modelValue | (value: number | null) | Fires with the normalized value. |
change | (value: number | null) | Fires together with update:modelValue. |
focus | (event: FocusEvent) | The native focus event. |
blur | (event: FocusEvent) | The native blur event; the field re-normalizes on blur. |
Exposed Methods
| Name | Description |
|---|---|
focus() | Focuses the native input. |
blur() | Blurs the native input. |
inputRef | Ref to the native input. |
Overview
- Empty input normalizes to
null. - Typed values clamp to
min/maxon blur, step results right away;precisionrounds after clamping. - Unparseable text left at blur falls back to the current value, or
nullif there is none. controls=falsehides the step buttons and keeps the native numeric field.readonlyanddisabledboth block stepping;disabledalso disables the field.- Inside a
TxFormItemit takes the id,aria-describedby,aria-invalidandrequired, and draws a red edge while the item shows an error; the form'sdisabledapplies too and blocks stepping.
Technologies
- Attrs other than
class/stylego to the native input. - Source:
packages/tuffex/packages/components/src/number-input/.
查看源码
packages/tuffex/packages/components/src/number-input/index.ts