Components/NumberInput

NumberInput

A numeric field with step buttons, clamping, and precision.

VerifiedSince 0.3.7

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, and step for percentages, quotas, and pagination.
  • Handle decimals with precision instead of rounding in the consumer after every event.
  • Set controls=false in dense table filters, where typing is faster.
  • Treat null as unset in validation and API mapping.

API Reference

Props

PropTypeDefaultDescription
modelValue / v-modelnumber | nullnullThe number; null when the field is empty.
minnumber-Minimum value.
maxnumber-Maximum value.
stepnumber1Increment of the step buttons and the native input.
precisionnumber-Decimal places to keep.
placeholderstring''Placeholder text.
disabledbooleanfalseDisables the field and the buttons.
readonlybooleanfalseMakes the field read-only and blocks stepping.
controlsbooleantrueShows the decrease and increase buttons.

Events

EventParamsDescription
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

NameDescription
focus()Focuses the native input.
blur()Blurs the native input.
inputRefRef to the native input.

Overview

  • Empty input normalizes to null.
  • Typed values clamp to min / max on blur, step results right away; precision rounds after clamping.
  • Unparseable text left at blur falls back to the current value, or null if there is none.
  • controls=false hides the step buttons and keeps the native numeric field.
  • readonly and disabled both block stepping; disabled also disables the field.

Technologies

  • Attrs other than class / style go to the native input.
  • Source: packages/tuffex/packages/components/src/number-input/.
查看源码
packages/tuffex/packages/components/src/number-input/index.ts