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 lang="ts">
import { ref } from 'vue'
import { NumberInput } from 'brutx-ui-vue'

const count = ref<number | null>(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>

API Reference ​

NumberInput — Props
NameTypeDefaultDescription
layout
"stacked" | "split" | undefined
"split"
Sets how the increment and decrement buttons are arranged around the input.
Details

Declared type

"stacked" | "split" | undefined

Literal values

  • "split"
  • "stacked"

Default value details

Resolved value
"split"

Source

NumberInput.vue:25

packages/ui/src/components/number-input/NumberInput.vue

variant
"default" | "success" | "error" | undefined
"default"
Sets the default, success, or error border state.
Details

Declared type

"default" | "success" | "error" | undefined

Literal values

  • "default"
  • "error"
  • "success"

Default value details

Resolved value
"default"

Source

NumberInput.vue:26

packages/ui/src/components/number-input/NumberInput.vue

errorMessage
string | undefined
undefined
Error text shown and associated with the input in the error variant.
Details

Declared type

string | undefined

Default value details

Resolved value
undefined

Source

NumberInput.vue:27

packages/ui/src/components/number-input/NumberInput.vue

placeholder
string | undefined
undefined
Placeholder shown when the input is empty; the current locale text is used when omitted.
Details

Declared type

string | undefined

Default value details

Resolved value
undefined

Source

NumberInput.vue:28

packages/ui/src/components/number-input/NumberInput.vue

ariaLabel
string | undefined
undefined
The accessible name passed to the internal numeric input. When ariaLabelledby is also provided, ariaLabelledby takes precedence.
Details

Declared type

string | undefined

Default value details

Resolved value
undefined

Source

NumberInput.vue:29

packages/ui/src/components/number-input/NumberInput.vue

ariaLabelledby
string | undefined
undefined
The ID of the label element passed to the internal numeric input; it takes precedence over ariaLabel.
Details

Declared type

string | undefined

Default value details

Resolved value
undefined

Source

NumberInput.vue:30

packages/ui/src/components/number-input/NumberInput.vue

class
string | undefined
undefined
Custom CSS classes added to the number input container.
Details

Declared type

string | undefined

Default value details

Resolved value
undefined

Source

NumberInput.vue:31

packages/ui/src/components/number-input/NumberInput.vue

iconSize
IconSize | undefined
"md"
Sets the size of the increment and decrement icons.
Details

Declared type

IconSize | undefined

Literal values

  • "2xl"
  • "lg"
  • "md"
  • "sm"
  • "xl"
  • "xs"

Referenced types

IconSize
Type definition — IconSize
export type IconSize = NonNullable<VariantProps<typeof iconSizeVariants>['size']>

Default value details

Resolved value
"md"

Source

NumberInput.vue:32

packages/ui/src/components/number-input/NumberInput.vue

sound
boolean | undefined
false
Enables a Web Audio click sound when a step control is activated.
Details

Declared type

boolean | undefined

Literal values

  • false
  • true

Default value details

Resolved value
false

Source

NumberInput.vue:34

packages/ui/src/components/number-input/NumberInput.vue

defaultValue
number | undefined
—
The initial numeric value used in uncontrolled mode.
Details

Declared type

number | undefined

Default value details

Not declared
—

Source

NumberInput.vue

packages/ui/src/components/number-input/NumberInput.vue

modelValue
Nullable
number | null | undefined
—
The current controlled number; null represents an empty value and can be bound with v-model.
Details

Declared type

number | null | undefined

Literal values

  • null

Default value details

Not declared
—

Source

NumberInput.vue

packages/ui/src/components/number-input/NumberInput.vue

min
number | undefined
—
The minimum allowed value and lower bound for decrementing.
Details

Declared type

number | undefined

Default value details

Not declared
—

Source

NumberInput.vue

packages/ui/src/components/number-input/NumberInput.vue

max
number | undefined
—
The maximum allowed value and upper bound for incrementing.
Details

Declared type

number | undefined

Default value details

Not declared
—

Source

NumberInput.vue

packages/ui/src/components/number-input/NumberInput.vue

step
number | undefined
—
The amount added or subtracted by each step control activation.
Details

Declared type

number | undefined

Default value details

Not declared
—

Source

NumberInput.vue

packages/ui/src/components/number-input/NumberInput.vue

stepSnapping
boolean | undefined
—
Aligns values to step intervals from min, or zero when min is omitted. When disabled, the last step can land on the range boundary.
Details

Declared type

boolean | undefined

Literal values

  • false
  • true

Default value details

Not declared
—

Source

NumberInput.vue

packages/ui/src/components/number-input/NumberInput.vue

focusOnChange
boolean | undefined
—
Whether to focus the input after its value changes through a step action.
Details

Declared type

boolean | undefined

Literal values

  • false
  • true

Default value details

Not declared
—

Source

NumberInput.vue

packages/ui/src/components/number-input/NumberInput.vue

formatOptions
Intl.NumberFormatOptions | undefined
—
Intl.NumberFormat options used to format the value and interpret locale-specific input.
Details

Declared type

Intl.NumberFormatOptions | undefined

Default value details

Not declared
—

Source

NumberInput.vue

packages/ui/src/components/number-input/NumberInput.vue

locale
string | undefined
—
The locale used for number formatting and input parsing.
Details

Declared type

string | undefined

Default value details

Not declared
—

Source

NumberInput.vue

packages/ui/src/components/number-input/NumberInput.vue

disabled
boolean | undefined
—
Disables the input and its increment and decrement controls.
Details

Declared type

boolean | undefined

Literal values

  • false
  • true

Default value details

Not declared
—

Source

NumberInput.vue

packages/ui/src/components/number-input/NumberInput.vue

readonly
boolean | undefined
—
Keeps the field focusable and included in form submission while preventing changes by typing, keyboard shortcuts, step buttons, or the wheel.
Details

Declared type

boolean | undefined

Literal values

  • false
  • true

Default value details

Not declared
—

Source

NumberInput.vue

packages/ui/src/components/number-input/NumberInput.vue

disableWheelChange
boolean | undefined
—
Prevents the mouse wheel from changing the current value.
Details

Declared type

boolean | undefined

Literal values

  • false
  • true

Default value details

Not declared
—

Source

NumberInput.vue

packages/ui/src/components/number-input/NumberInput.vue

invertWheelChange
boolean | undefined
—
Reverses the mapping between wheel direction and value increment or decrement.
Details

Declared type

boolean | undefined

Literal values

  • false
  • true

Default value details

Not declared
—

Source

NumberInput.vue

packages/ui/src/components/number-input/NumberInput.vue

id
string | undefined
—
The DOM id passed to the internal input control.
Details

Declared type

string | undefined

Default value details

Not declared
—

Source

NumberInput.vue

packages/ui/src/components/number-input/NumberInput.vue

asChild
boolean | undefined
—
Enables composition mode, merging the component props and behavior into its single child.
Details

Declared type

boolean | undefined

Literal values

  • false
  • true

Default value details

Not declared
—

Source

NumberInput.vue

packages/ui/src/components/number-input/NumberInput.vue

as
AsTag | Component | undefined
—
The tag or Vue component used to render the root element.
Details

Declared type

AsTag | Component | undefined

Literal values

  • "a"
  • "button"
  • "div"
  • "form"
  • "h2"
  • "h3"
  • "img"
  • "input"
  • "label"
  • "li"
  • "nav"
  • "ol"
  • "p"
  • "span"
  • "svg"
  • "template"
  • "ul"

Default value details

Not declared
—

Source

NumberInput.vue

packages/ui/src/components/number-input/NumberInput.vue

name
string | undefined
—
The name of the internal form control for form submission.
Details

Declared type

string | undefined

Default value details

Not declared
—

Source

NumberInput.vue

packages/ui/src/components/number-input/NumberInput.vue

required
boolean | undefined
—
Marks the internal input control as required.
Details

Declared type

boolean | undefined

Literal values

  • false
  • true

Default value details

Not declared
—

Source

NumberInput.vue

packages/ui/src/components/number-input/NumberInput.vue

NumberInput — Events
NameSignature or typeDescription
@update:modelValue
[value: number | null]
Emits a new value when an edit is confirmed or a step changes the value. Confirming an empty field emits null.
Details

Declared type

[value: number | null]

Literal values

  • null

Source

NumberInput.vue

packages/ui/src/components/number-input/NumberInput.vue

Committing and stepping ​

  • Clearing the field and pressing Enter or leaving the field commits null. Type the bound value and any update:modelValue handler parameter as number | null. Its form value is empty, and a required field fails validation. The parent decides the final value in controlled mode. A form reset restores the initial uncontrolled value or the current controlled value.
  • Step buttons, arrow keys, and the wheel follow the same stepping rules. With step snapping disabled, the last step can land on min or max. The formatOptions control display precision, while stepping and native form submission keep the actual numeric value within the range.

Accessibility ​

  • Keyboard: Tab focuses the input, Up/Down arrows step, Page Up/Page Down take larger steps, and Home/End move to the bounds. Enter/Space activate a focused step button. A read-only field stays focusable and keeps its form value while blocking value changes.
  • ARIA attributes: Increment/decrement buttons automatically set aria-label (e.g. "Increase"/"Decrease"), input sets aria-valuemin, aria-valuemax, aria-valuenow attributes
  • Accessible name: Name the numeric input with a native label associated through id, aria-label, or aria-labelledby. When both aria-label and aria-labelledby are provided, aria-labelledby takes precedence. Other ARIA and native input attributes reach the numeric control
  • 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
  • Motion & sound degradation: The Drum Ticker micro-animation on value change is disabled automatically under prefers-reduced-motion; the sound effect follows the browser autoplay policy and stays silent before user interaction

Brute force builds.