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>
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 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 | |||
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 | — | Whether input values are aligned to multiples of step. |
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 | — | Prevents direct value editing without disabling the component. |
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 | [val: number] | Emits the new numeric value after typing or stepping so v-model can be updated. |
DetailsDeclared type[val: number] Sourcepackages/ui/src/components/number-input/NumberInput.vue | ||
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 setsaria-valuemin,aria-valuemax,aria-valuenowattributes - 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