Skip to main content
Vuetify0 is now in alpha!
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

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

API Reference

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

Ctrl+/