Skip to content

NumberBox ​

17:06

Description ​

Increments/decrements a value: tap the +/- buttons or type directly, with the value two-way bound via v-model. Supports a step size, min / max range limits and long-press continuous change; positive-integer restricts input to positive integers by default.

Compatibility ​

PlatformSupport
App✅ Supported
H5✅ Supported
WeChat Mini Program✅ Supported

Examples ​

Basic Usage ​

Bind value via v-model; modify by tapping +/- or manual input.

View source
vue
<template>
    <ux-number-box v-model="val" />
</template>

<script setup lang="uts">
const val = ref<number>(1);
</script>

Step Size ​

Set the increment/decrement via the step prop; here it is 10.

View source
vue
<template>
    <ux-number-box v-model="val" :step="10" />
</template>

<script setup lang="uts">
const val = ref<number>(10);
</script>

Range Limit ​

Limit min and max values via min and max props; here 5-50.

View source
vue
<template>
    <ux-number-box v-model="val" :min="5" :max="50" />
</template>

<script setup lang="uts">
const val = ref<number>(5);
</script>

Disabled ​

When disabled=true, all operations are disabled.

View source
vue
<template>
    <ux-number-box v-model="val" :disabled="true" />
</template>

<script setup lang="uts">
const val = ref<number>(1);
</script>

Custom Size ​

Customize size via size, input-width, input-height props.

View source
vue
<template>
    <ux-number-box v-model="val" :size="15" :input-width="60" :input-height="30" />
</template>

<script setup lang="uts">
const val = ref<number>(1);
</script>

API ​

Props ​

PropertyDescriptionTypeDefaultVersion
customStyleCustom root element styleUTSJSONObject--
customClassCustom root element style classstring''-
modelValueInitial input value (default 1)number1-
bgColorBackground color of the input and buttonsstring''-
minMinimum value the user can enter (default 0)number0-
maxMaximum value the user can enter (default 50000)number99999-
stepStep size added or subtracted each time (default 1)number1-
disabledWhether to disable all operations (default false)booleanfalse-
sizeFont size of the input text and buttons, in px (default 13)number | string13-
colorColor of the input text and the +/- iconsstring''-
inputWidthInput width in px (default 40)number | string40-
inputHeightHeight of the input and buttons in px (default 25)number | string25-
indexDistinguishes which input changed in event callbacksnumber | string''-
disabledInputWhether to forbid manual typing in the input (default false)booleanfalse-
cursorSpacingDistance between the cursor and the keyboard (default 50)number | string100-
longPressWhether to enable long-press continuous increment/decrement (default true)booleantrue-
pressTimeInterval between repeats after a long press starts, in ms (default 125)number | string250-
positiveIntegerWhether only positive integers can be entered (default true)booleantrue-
validateStateValidation error state; turns the border red on errorbooleanfalse-

Events ​

EventDescriptionParamsVersion
changeFires when the input content changesvalue: UTSJSONObject-
blurFires when the input loses focusvalue: UTSJSONObject-
focusFires when the input gains focus--
minusFires when the minus button is tappedvalue: UTSJSONObject-
plusFires when the plus button is tappedvalue: UTSJSONObject-

Slots ​

ux-number-box has no slots.

Notes ​

  • Manual input accepts non-negative integers only: on blur the value is checked with /^\d+$/, and input containing a decimal point, a minus sign or a leading zero is reset to min, then clamped to min / max.
  • positive-integer (default true) blocks negative numbers and decimals while typing, falling back to the last valid value.
  • Tapping +/- so the result would exceed min / max does not update the value (the tap is ignored); at a boundary or when disabled, the button is shown grayed out.
  • long-press is enabled by default: holding a +/- button repeats every press-time (default 250ms) and stops on release.
  • disabled-input only forbids manual typing; the +/- buttons still work. disabled disables everything (input and buttons).
  • The component can inject the ux-form-item context: value changes and blur trigger its validation, and validate-state or a failed form validation adds a red border on the root.