NumberInput
Numeric input with step controls, clamping, and precision normalization.
NumberInput
Basic Usage
NumberInput
Loading demo...
Interaction Contract
- Empty input normalizes to
null. - Non-finite input falls back to the previous value, or
nullwhen no value exists. min/maxclamp typed values and step button results.precisionappliesNumber(value.toFixed(precision))after clamping.controls=falsehides both step buttons and keeps the native numeric field.readonlyanddisabledblock step buttons;disabledalso disables the input.
API
Props
| Prop | Type | Default | Description |
|---|---|---|---|
modelValue / v-model | number | null | null | Current numeric value. |
min | number | - | Minimum value. |
max | number | - | Maximum value. |
step | number | 1 | Step size used by controls and native input. |
precision | number | - | Decimal precision after normalization. |
placeholder | string | '' | Native input placeholder. |
disabled | boolean | false | Disable input and controls. |
readonly | boolean | false | Make input read-only and block controls. |
controls | boolean | true | Show decrease/increase buttons. |
Events
| Event | Params | Description |
|---|---|---|
update:modelValue | (value: number | null) | v-model update after normalization. |
change | (value: number | null) | Emitted with the same normalized value. |
focus | (event: FocusEvent) | Native focus event. |
blur | (event: FocusEvent) | Native blur event; also re-normalizes the field. |
Exposed Methods
| Method | Description |
|---|---|
focus() | Focus the native input. |
blur() | Blur the native input. |
inputRef | Native input ref. |
Slots
TxNumberInput does not expose slots. Use adjacent form help text or wrapper layout for labels, prefixes, suffixes, and validation copy.
Best Practices
- Prefer explicit
min,max, andstepfor percentages, quotas, and pagination controls. - Use
precisionfor decimals rather than rounding in the consumer after every event. - Hide controls for dense table filters where keyboard entry is faster.
- Treat
nullas the unset state in validation and API payload mapping.
Review Notes
- Source:
packages/tuffex/packages/components/src/number-input/src/TxNumberInput.vueconfirms normalization, clamping, precision handling, attr forwarding, step controls, focus state, and exposed helpers. - Verified coverage: Coverage:
packages/tuffex/packages/components/src/number-input/__tests__/number-input.test.tscovers numeric attrs, normalized input, clamped step controls, hidden controls, and focus helper exposure. - Export:
packages/tuffex/packages/components/src/number-input/index.tswraps the component withwithInstalland exportsTxNumberInputInstance.
Source
查看源码
packages/tuffex/packages/components/src/number-input/index.ts