Skip to main content
Vuetify0 is now a release candidate!
Vuetify0 Logo
Theme
Mode
Palettes
Accessibility
Vuetify One
Sign in to Vuetify One

Access premium tools across the Vuetify ecosystem — Bin, Play, Studio, and more.

Not a subscriber? See what's included

createNumberField

Numeric value with locale-aware formatting, step snapping, and field validation. Give it a min/max/step, get increment/decrement, formatted display, and parse/commit for text input.

Usage

ts
import { createNumberField } from '@vuetify/v0'
import { shallowRef } from 'vue'

// Basic — standalone counter
const field = createNumberField({ min: 0, max: 100, step: 1 })
field.increment()       // 1
field.increment(5)      // 6  (multiplier)
field.value.value       // 6
field.display.value     // '6'

// Currency formatting
const price = shallowRef<number | null>(42)
const currency = createNumberField({
  value: price,
  min: 0,
  max: 10000,
  step: 0.01,
  locale: 'en-US',
  format: { style: 'currency', currency: 'USD' },
})
currency.display.value  // '$42.00'
currency.parse('$1,234.56')  // 1234.56

// With validation
const validated = createNumberField({
  min: 1,
  max: 100,
  rules: [v => v !== null || 'Required'],
})
await validated.input.validate()
validated.input.errors.value  // ['Required']

Architecture

createNumberField Architecture

Use controls to zoom and pan. Click outside or press Escape to close.

createNumberField Architecture

createNumeric provides pure math (step, clamp, snap, boundary checks). createInput provides field state (dirty, pristine, focus, validation). Intl.NumberFormat provides locale-aware formatting and parsing.

Reactivity

PropertyTypeReactiveDescription
valueRef<number | null>YesCurrent numeric value
displayReadonly<Ref<string>>YesFormatted display string
canIncrementReadonly<Ref<boolean>>YesWhether value can go up
canDecrementReadonly<Ref<boolean>>YesWhether value can go down
numericNumericContextNoUnderlying numeric math context
inputInputContextPartialField state (focus, dirty, validation)
increment(n?)(multiplier?: number) => voidIncrement by step * multiplier
decrement(n?)(multiplier?: number) => voidDecrement by step * multiplier
floor()() => voidSet to minimum
ceil()() => voidSet to maximum
formatValue(v)(value: number) => stringFormat a number
parse(text)(text: string) => number | nullParse text to number
commit()() => voidSnap and optionally clamp

Examples

Build your own number input

This example builds a reusable numeric field entirely from createNumberField, without reaching for the NumberField component. useOrder creates two field contexts over shared value refs — a unit price formatted as USD currency and an integer quantity — then derives a live order total by calling priceField.formatValue on the product of the two raw values. Keeping the numbers in value and the formatting in display/formatValue is what lets the total reuse the price field’s currency formatter without re-implementing Intl.

NumberStepper is the headless input you would otherwise get from the component. It renders a text box plus a pair of stepper buttons and wires the four interaction surfaces by hand: decrement/increment on the buttons, canDecrement/canIncrement to disable them at the min/max boundaries, display for the formatted read-only view, and parse + commit on blur to turn typed text back into a clamped, step-snapped number. A local draft string holds the raw text only while the field is focused, so typing never fights the formatter and the cursor never jumps.

Reach for this pattern when you need numeric input with custom markup the component’s structure does not allow — a stepper baked into a larger control, an inline editable total, or a non-standard layout. When you just need a labelled, accessible spin-button with errors, use the NumberField component instead; for the pure step math underneath, see createNumeric.

FileRole
useOrder.tsCreates the price and quantity field contexts and derives the formatted total
NumberStepper.vueRenders a custom text input plus stepper buttons from a field context
order-calculator.vueWires the composable to two steppers and shows the live total
Unit price
Quantity
Order total$39.98

FAQ

Discord
Need help? Join our community for support and discussions ↗

API Reference

The following API details are for the createNumberField composable.
Was this page helpful?

Ctrl+/