Skip to content

NumberInput

A text input for numeric values, with built-in long-press continuous scrolling logic for the increment/decrement buttons, and support for min, max, and precision step adjustments.

Demo

Preview

Installation

pnpm dlx brutx-vue@latest add number-input

Usage

vue
<script setup>
import { ref } from 'vue'
import { NumberInput } from 'brutx-ui-vue'

const count = ref(5)
</script>

<template>
    <NumberInput v-model="count" :min="0" :max="10" :step="1" />
</template>

Variants

NumberInput provides two button layout modes, configured via the layout prop:

Layout PropDescription
split (default)Split sides: Minus button on the left, plus button on the right, with a bold symmetrical feel.
stackedRight-stacked: Increment/decrement buttons stacked vertically on the right.
vue
<template>
    <!-- Split layout -->
    <NumberInput v-model="count" layout="split" />

    <!-- Stacked layout -->
    <NumberInput v-model="count" layout="stacked" />
</template>

Border Style Variants

Set different border styles via the variant prop for form validation state feedback:

VariantDescription
defaultStandard border
errorError border with danger color focus shadow
successSuccess border with success color focus shadow
vue
<template>
    <NumberInput v-model="count" variant="default" />
    <NumberInput v-model="count" variant="error" />
    <NumberInput v-model="count" variant="success" />
</template>

Props

PropTypeDefaultDescription
modelValuenumber | nullCurrent input value
defaultValuenumberDefault value when uncontrolled
minnumberMinimum allowed value
maxnumberMaximum allowed value
stepnumber1Increment/decrement step size
stepSnappingbooleantrueWhether to enable step snapping; when false, value does not auto-align to step multiples
focusOnChangebooleanfalseWhether to auto-focus the input when value changes
formatOptionsIntl.NumberFormatOptionsNumber formatting options, affects display and allowed input characters
localestringLocale for formatting and currency
layout'split' | 'stacked''split'Layout structure for the adjustment buttons
variant'default' | 'error' | 'success''default'Border style variant
errorMessagestringError message text, only displayed when variant="error"
placeholderstringundefinedPlaceholder; uses internationalized default when not set
disabledbooleanfalseWhether to disable the input and buttons
readonlybooleanfalseWhether readonly
disableWheelChangebooleanfalseWhether to prevent mouse wheel from changing the value
invertWheelChangebooleanfalseWhether to invert the scroll wheel direction
namestringForm field name, submitted with the form
requiredbooleanfalseWhether the field is required
idstringElement id attribute
iconSize'xs' | 'sm' | 'default' | 'lg' | 'xl' | '2xl''default'Size of the increment/decrement button icons
asstring | Component'div'Tag or component to render the root element as
asChildbooleanfalseWhether to enable composition mode, not rendering its own DOM and passing props to the child element
classstringundefinedCustom CSS class for the container

Events

EventPayloadDescription
update:modelValue(val: number)Triggered when the input value changes

Accessibility

  • Keyboard: Input supports Tab focus, increment/decrement buttons support Enter/Space trigger, Up/Down arrow keys adjust the value
  • ARIA attributes: Increment/decrement buttons automatically set aria-label (e.g. "Increase"/"Decrease"), input sets aria-valuemin, aria-valuemax, aria-valuenow attributes
  • Form integration: Supports name, required, disabled, readonly and other native form attributes, compatible with form validation
  • Focus management: focusOnChange prop controls whether to auto-focus on value change; all interaction is disabled in disabled state

Brute force builds.