vael-ui v0.5.7

Forms & inputs

Layout

InputNumber

A number field with steppers and locale-aware formatting and parsing. Use it for quantities, prices and percentages.

Validating a form? vael-form wires this up with a schema

Install

import { InputNumber } from 'vael-ui'

Playground

Placement, behaviour and animation

Usage
<script setup lang="ts">
import { ref } from 'vue'
import { InputNumber } from 'vael-ui'

const value = ref<number | null>(null)
</script>

<template>
  <InputNumber
    locale="en-US"
    placeholder="Type here…"
    v-model="value"
  />
</template>

Props

NameTypeDefaultDescription
minnumberLowest allowed value; blur, Enter and the steppers clamp the value to it.
maxnumberHighest allowed value; blur, Enter and the steppers clamp the value to it.
stepnumber1Amount the steppers and the arrow keys add or remove.
localestringBCP-47 locale for formatting and parsing numbers. When unset, the runtime locale applies.
mode'decimal' | 'currency' | 'percent''decimal'Number format: plain decimal, currency (needs currency) or percent.
currencystringISO 4217 currency code; required when mode is 'currency'.
minFractionDigitsnumberMinimum number of decimal places shown.
maxFractionDigitsnumberMaximum number of decimal places shown.
useGroupingbooleantrueShows locale grouping separators, such as thousands commas.
prefixstringLiteral text before the formatted number, outside Intl formatting, such as a unit label.
suffixstringLiteral text after the formatted number, such as a unit label.
controlsbooleantrueShows the increment and decrement buttons.
stepperPosition'split' | 'end''end''end' stacks a +/- column after the value; 'split' puts one full-height button on each side.
allowEmptybooleantrueWhen false, blurring an empty field sets the value to min ?? 0 instead of null.
size'sm' | 'md' | 'lg''md'Control size.
disabledbooleanfalseDisables the input and blocks interaction. A disabled parent Field also disables it.
readonlybooleanfalseMakes the value read-only while keeping it focusable and selectable.
invalidbooleanfalseStandalone override; ORed with the nearest Field's error state.
placeholderstringText shown while the input is empty.
namestringNative name on the input; a plain <form> submits the formatted text.
scrubnumber | booleanfalseDrag sideways on the field, while you're not typing in it, to change the value: one step per this many pixels, ten with Shift held. true is 4 px. A click without a drag still focuses the field for typing.
animatedbooleanfalseRolls the digits to each new value from the steppers, the arrow keys or your code, like AnimatedNumber. Typing shows the plain input.
motionInputNumberMotionHow it moves: its appearance ({ initial: { root: { opacity: 0, y: 4 } } }) and its states ({ states: { invalid: { root: { x: [0, -6, 6, 0] } } } }). false turns its own animation off.
uiPartial<Record<'root' | 'input' | 'increment' | 'decrement', UiPartValue>>Class and style overrides for each part.
modelValuenumber | nullnullNumeric value; null when the field is empty.

Events

NameTypeDescription
update:modelValue(value: number | null)Fires when modelValue changes (v-model).

Slots

NameTypeDescription
startanyInline leading content, before the value and the 'split' mode decrement button.
endanyInline trailing content, before the stepper buttons.
display{ value: string; placeholder: string; focused: boolean; }Draws the text yourself over the field's own text, as Input's #display; it replaces the rolling digits of animated. value is the formatted text.

Exposed

NameTypeDescription
elHTMLElement | nullRoot element (the frame around the input).
inputElHTMLInputElement | nullNative <input> element.
increment() => voidAdds one step, clamped to max. No-op when disabled or read-only.
decrement() => voidSubtracts one step, clamped to min. No-op when disabled or read-only.
partsRecord<string, HTMLElement | HTMLElement[] | null>Its elements by part name, for your own animation; a repeated part is an array.

Motion New

InputNumber: its appearance and states.

<InputNumber
  :motion="{ states: { invalid: { root: { scale: 1.04 } } } }"
/>
NameTypeDescription
initialexitrootinputincrementdecrementSets where each part comes in from and leaves to: any CSS property, plus x, y and blur. A plain number is px, or degrees for rotate.
statesinvaliddisabledfocusSets values per part that hold while a state is on. An array is a set of keyframes that plays once as the state turns on, such as a shake on invalid.
enterleave(parts, context) => animationAnimates the parts with GSAP, motion or element.animate(). Return the animation and the component waits for it, and stops it if interrupted.
springdurationeasing{ damping, response } | number | stringTimes all of it: a spring, or a duration in ms with an easing. Never both.
falsebooleanTurns its motion off, for an animation of your own on its exposed elements.

Accessibility

Follows the Spinbutton pattern from the WAI-ARIA Authoring Practices Guide.

KeyAction
ArrowUpAdds one step, up to max.
ArrowDownSubtracts one step, down to min.
HomeSets the value to min, when min is set.
EndSets the value to max, when max is set.
EnterClamps the typed value to min and max and formats it.
  • A text input with role="spinbutton", aria-valuenow, aria-valuemin and aria-valuemax.
  • The stepper buttons are out of the tab order (tabindex="-1") and labeled “Increase” and “Decrease”; the arrow keys do the same job.
  • Keys do nothing while it is disabled or read-only. Leaving the field clamps and formats the value, like Enter.
  • It is built on Input, so Field labels it the same way.