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
步进点击时播放机械咔哒声(首次交互后生效)
Installation
pnpm dlx brutx-vue@latest add number-inputUsage
<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 Prop | Description |
|---|---|
split (default) | Split sides: Minus button on the left, plus button on the right, with a bold symmetrical feel. |
stacked | Right-stacked: Increment/decrement buttons stacked vertically on the right. |
<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:
| Variant | Description |
|---|---|
default | Standard border |
error | Error border with danger color focus shadow |
success | Success border with success color focus shadow |
<template>
<NumberInput v-model="count" variant="default" />
<NumberInput v-model="count" variant="error" />
<NumberInput v-model="count" variant="success" />
</template>API Reference
| Name | Type | Default | Description |
|---|---|---|---|
layout | "stacked" | "split" | undefined | "split" | Sets how the increment and decrement buttons are arranged around the input. |
DetailsDeclared type"stacked" | "split" | undefined Literal values
Default value details
Sourcepackages/ui/src/components/number-input/NumberInput.vue | |||
variant | "default" | "success" | "error" | undefined | "default" | Sets the default, success, or error border state. |
DetailsDeclared type"default" | "success" | "error" | undefined Literal values
Default value details
Sourcepackages/ui/src/components/number-input/NumberInput.vue | |||
errorMessage | string | undefined | undefined | Error text shown and associated with the input in the error variant. |
DetailsDeclared typestring | undefined Default value details
Sourcepackages/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. |
DetailsDeclared typestring | undefined Default value details
Sourcepackages/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. |
DetailsDeclared typestring | undefined Default value details
Sourcepackages/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. |
DetailsDeclared typestring | undefined Default value details
Sourcepackages/ui/src/components/number-input/NumberInput.vue | |||
class | string | undefined | undefined | Custom CSS classes added to the number input container. |
DetailsDeclared typestring | undefined Default value details
Sourcepackages/ui/src/components/number-input/NumberInput.vue | |||
iconSize | IconSize | undefined | "md" | Sets the size of the increment and decrement icons. |
DetailsDeclared typeIconSize | undefined Literal values
Referenced types IconSize Type definition — IconSizeexport type IconSize = NonNullable<VariantProps<typeof iconSizeVariants>['size']> Default value details
Sourcepackages/ui/src/components/number-input/NumberInput.vue | |||
sound | boolean | undefined | false | Enables a Web Audio click sound when a step control is activated. |
DetailsDeclared typeboolean | undefined Literal values
Default value details
Sourcepackages/ui/src/components/number-input/NumberInput.vue | |||
defaultValue | number | undefined | — | The initial numeric value used in uncontrolled mode. |
DetailsDeclared typenumber | undefined Default value details
Sourcepackages/ui/src/components/number-input/NumberInput.vue | |||
modelValueNullable | number | null | undefined | — | The current controlled number; null represents an empty value and can be bound with v-model. |
DetailsDeclared typenumber | null | undefined Literal values
Default value details
Sourcepackages/ui/src/components/number-input/NumberInput.vue | |||
min | number | undefined | — | The minimum allowed value and lower bound for decrementing. |
DetailsDeclared typenumber | undefined Default value details
Sourcepackages/ui/src/components/number-input/NumberInput.vue | |||
max | number | undefined | — | The maximum allowed value and upper bound for incrementing. |
DetailsDeclared typenumber | undefined Default value details
Sourcepackages/ui/src/components/number-input/NumberInput.vue | |||
step | number | undefined | — | The amount added or subtracted by each step control activation. |
DetailsDeclared typenumber | undefined Default value details
Sourcepackages/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. |
DetailsDeclared typeboolean | undefined Literal values
Default value details
Sourcepackages/ui/src/components/number-input/NumberInput.vue | |||
focusOnChange | boolean | undefined | — | Whether to focus the input after its value changes through a step action. |
DetailsDeclared typeboolean | undefined Literal values
Default value details
Sourcepackages/ui/src/components/number-input/NumberInput.vue | |||
formatOptions | Intl.NumberFormatOptions | undefined | — | Intl.NumberFormat options used to format the value and interpret locale-specific input. |
DetailsDeclared typeIntl.NumberFormatOptions | undefined Default value details
Sourcepackages/ui/src/components/number-input/NumberInput.vue | |||
locale | string | undefined | — | The locale used for number formatting and input parsing. |
DetailsDeclared typestring | undefined Default value details
Sourcepackages/ui/src/components/number-input/NumberInput.vue | |||
disabled | boolean | undefined | — | Disables the input and its increment and decrement controls. |
DetailsDeclared typeboolean | undefined Literal values
Default value details
Sourcepackages/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. |
DetailsDeclared typeboolean | undefined Literal values
Default value details
Sourcepackages/ui/src/components/number-input/NumberInput.vue | |||
disableWheelChange | boolean | undefined | — | Prevents the mouse wheel from changing the current value. |
DetailsDeclared typeboolean | undefined Literal values
Default value details
Sourcepackages/ui/src/components/number-input/NumberInput.vue | |||
invertWheelChange | boolean | undefined | — | Reverses the mapping between wheel direction and value increment or decrement. |
DetailsDeclared typeboolean | undefined Literal values
Default value details
Sourcepackages/ui/src/components/number-input/NumberInput.vue | |||
id | string | undefined | — | The DOM id passed to the internal input control. |
DetailsDeclared typestring | undefined Default value details
Sourcepackages/ui/src/components/number-input/NumberInput.vue | |||
asChild | boolean | undefined | — | Enables composition mode, merging the component props and behavior into its single child. |
DetailsDeclared typeboolean | undefined Literal values
Default value details
Sourcepackages/ui/src/components/number-input/NumberInput.vue | |||
as | AsTag | Component | undefined | — | The tag or Vue component used to render the root element. |
DetailsDeclared typeAsTag | Component | undefined Literal values
Default value details
Sourcepackages/ui/src/components/number-input/NumberInput.vue | |||
name | string | undefined | — | The name of the internal form control for form submission. |
DetailsDeclared typestring | undefined Default value details
Sourcepackages/ui/src/components/number-input/NumberInput.vue | |||
required | boolean | undefined | — | Marks the internal input control as required. |
DetailsDeclared typeboolean | undefined Literal values
Default value details
Sourcepackages/ui/src/components/number-input/NumberInput.vue | |||
| Name | Signature or type | Description |
|---|---|---|
@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. |
DetailsDeclared type[value: number | null] Literal values
Sourcepackages/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 anyupdate:modelValuehandler parameter asnumber | 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
minormax. TheformatOptionscontrol 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 setsaria-valuemin,aria-valuemax,aria-valuenowattributes - Accessible name: Name the numeric input with a native label associated through
id,aria-label, oraria-labelledby. When botharia-labelandaria-labelledbyare provided,aria-labelledbytakes precedence. Other ARIA and native input attributes reach the numeric control - Form integration: Supports
name,required,disabled,readonlyand other native form attributes, compatible with form validation - Focus management:
focusOnChangeprop controls whether to auto-focus on value change; all interaction is disabled indisabledstate - Motion & sound degradation: The Drum Ticker micro-animation on value change is disabled automatically under
prefers-reduced-motion; thesoundeffect follows the browser autoplay policy and stays silent before user interaction