Skip to content

InputNumber

Composed of increase button, decrease button, and input box, used for entering or adjusting numbers within a certain range.

Component Type

Basic Usage

Bind the input value through v-model, and listen to value changes through the change event.

html
<wd-input-number v-model="value" @change="handleChange" />
typescript
import { ref } from 'vue'

const value = ref<number>(1)

function handleChange({ value }) {
  console.log(value)
}

Component State

Disabled

After setting disabled, both buttons and the input box are inoperable.

html
<wd-input-number v-model="value" disabled />

Disable Input Box

After setting disable-input, only adjusting values through buttons is allowed.

html
<wd-input-number v-model="value" disable-input @change="handleChange" />

Disable Minus Button

The minus button can be disabled separately.

html
<wd-input-number v-model="value" disable-minus @change="handleChange" />

Disable Plus Button

The plus button can be disabled separately.

html
<wd-input-number v-model="value" disable-plus @change="handleChange" />

Component Variant

Theme Style

Switch different visual styles through theme, optional values are default, primary, outline-split, outline.

html
<wd-input-number v-model="value1" theme="default" />
<wd-input-number v-model="value2" theme="primary" />
<wd-input-number v-model="value3" theme="outline-split" />
<wd-input-number v-model="value4" theme="outline" />

Rounded Style

After setting round, the buttons can be displayed in a rounded style.

html
<wd-input-number v-model="value" round theme="primary" />

Component Style

Set Step

After setting step, each increase or decrease will change according to the corresponding step.

html
<wd-input-number v-model="value" :step="2" @change="handleChange" />

Set Minimum and Maximum Values

Control the inputtable range through min and max.

html
<wd-input-number v-model="value" :min="3" :max="10" @change="handleChange" />

Set Decimal Precision

Control the result precision through precision.

html
<wd-input-number v-model="value" :precision="1" :step="0.1" @change="handleChange" />

Strict Step

After setting step-strictly, the input value will be corrected to a multiple of step when the change is completed.

html
<wd-input-number v-model="value" step-strictly :step="2" @change="handleChange" />

Strict Step and Boundary Limit

When setting step-strictly, min, and max at the same time, the component will automatically correct to the closest step value within the legal range.

html
<wd-input-number v-model="value" step-strictly :step="2" :min="3" :max="15" @change="handleChange" />

Modify Input Box Width

Set the input box width through input-width, supporting numbers and strings with units.

html
<wd-input-number v-model="value" input-width="70px" @change="handleChange" />

Special Usage

No Input Box

After setting without-input, only plus and minus buttons are displayed.

html
<wd-input-number v-model="value" without-input @change="handleChange" />

Allow Null Value

After setting allow-null, the input box allows empty values, which can be used with placeholder.

html
<wd-input-number v-model="value" allow-null placeholder="Unlimited" input-width="70px" @change="handleChange" />
typescript
const value = ref<number | string>('')

Not Allow Null Value but Can Be Temporarily Deleted

When allow-null is false, the input box can be temporarily cleared, but it will be automatically corrected back to a legal value after blurring.

html
<wd-input-number v-model="value" :allow-null="false" :min="1" @change="handleChange" />

Keyboard Pops Up Without Pushing Page Up

After setting adjust-position="false", the page is not automatically pushed up when the keyboard pops up.

html
<wd-input-number v-model="value" :adjust-position="false" @change="handleChange" />

Non-Immediate Update Mode

After setting immediate-change="false", the input box content change will not immediately trigger change, only triggered on blur or button click.

html
<wd-input-number v-model="value1" :immediate-change="true" @change="handleChange" />
<wd-input-number v-model="value2" :immediate-change="false" @change="handleChange" />

Auto Correct on Initialization

Set update-on-init to control whether the component corrects the value to a result that conforms to the rules during initialization.

html
<wd-input-number v-model="value1" :update-on-init="true" :min="3" :max="15" :step="2" step-strictly @change="handleChange" />
<wd-input-number v-model="value2" :update-on-init="false" :min="3" :max="15" :step="2" step-strictly @change="handleChange" />

Async Change

Validation and interception can be performed before the value changes through before-change.

html
<wd-input-number v-model="value" :before-change="beforeChange" />
typescript
import { ref } from 'vue'
import { useToast } from '@/uni_modules/wot-ui'
import type { InputNumberBeforeChange } from '@/uni_modules/wot-ui/components/wd-input-number/types'

const { loading, close } = useToast()
const value = ref<number>(1)

const beforeChange: InputNumberBeforeChange = (value) => {
  loading({ msg: `Updating to ${value}...` })
  return new Promise((resolve) => {
    setTimeout(() => {
      close()
      resolve(true)
    }, 500)
  })
}

Long Press to Add/Subtract

After setting long-press, support long pressing the button to continuously increase or decrease.

html
<wd-input-number v-model="value" long-press @change="handleChange" />

Attributes

ParameterDescriptionTypeDefault Value
v-modelBinding valuenumber | string-
minMinimum valuenumber1
maxMaximum valuenumberNumber.MAX_SAFE_INTEGER
stepStep valuenumber1
step-strictlyWhether to strictly increase or decrease by step valuebooleanfalse
precisionNumeric precisionnumber | string0
disabledWhether to disablebooleanfalse
disable-input v0.2.14Whether to disable the input boxbooleanfalse
disable-minus v0.2.14Whether to disable the minus buttonbooleanfalse
disable-plus v0.2.14Whether to disable the plus buttonbooleanfalse
without-inputWhether to not display the input boxbooleanfalse
input-widthInput box width, supporting numbers and strings with unitsnumber | string-
allow-nullWhether to allow input value to be empty, set to true to allow passing empty stringbooleanfalse
placeholderInput box placeholder textstring''
adjust-position v1.3.11Whether to automatically push up the page when the keyboard pops upbooleantrue
before-change v1.6.0Triggered before value change, return false to prevent value update, support returning Promise<boolean>(value: number | string) => boolean | Promise<boolean>-
long-press v1.8.0Whether to allow long press to add/subtractbooleanfalse
immediate-change v1.10.0Whether to immediately respond to input changes, when false, only update on blur or button clickbooleantrue
update-on-init v1.10.0Whether to update v-model to the corrected value during initializationbooleantrue
input-type v1.10.0Input box type, optional values are number, digit'number' | 'digit'digit
themeTheme style, optional values are default, outline, outline-split, primaryInputNumberThemedefault
roundWhether to enable rounded stylebooleanfalse
custom-classRoot node custom class namestring''
custom-styleRoot node custom stylestring''

Events

Event NameDescriptionParameters
changeTriggered when value is modified{ value }
focusTriggered when the input box gets focus{ value, height }
blurTriggered when the input box loses focus{ value }
update:modelValueTriggered when v-model is updatednumber | string

External Style Classes

Class NameDescription
custom-classRoot node style class

主题定制

CSS 变量

组件提供了下列 CSS 变量,可用于自定义样式,使用方法请参考 ConfigProvider 全局配置

名称默认值描述
--wot-input-number-action-size$n-28操作按钮尺寸
--wot-input-number-action-bg$filled-bottom操作按钮背景色
--wot-input-number-action-color$icon-secondary操作按钮颜色
--wot-input-number-action-border-radius$radius-main操作按钮圆角
--wot-input-number-action-border-radius-full$radius-radius-full圆角模式操作按钮圆角
--wot-input-number-action-disabled-color$icon-disabled操作按钮禁用颜色
--wot-input-number-action-divider-width$stroke-main操作按钮分割线宽度
--wot-input-number-action-divider-bg$filled-oppo操作按钮分割线颜色
--wot-input-number-action-divider-split-bg$filled-strong分离模式分割线颜色
--wot-input-number-action-divider-split-height$n-18分离模式分割线高度
--wot-input-number-icon-size$n-12图标尺寸
--wot-input-number-icon-weight$n-3图标线宽
--wot-input-number-input-width$n-36输入框宽度
--wot-input-number-input-height$n-28输入框高度
--wot-input-number-input-padding$spacing-zero $padding-tight输入框内边距
--wot-input-number-input-bg$filled-bottom输入框背景色
--wot-input-number-input-color$text-main输入框文字颜色
--wot-input-number-font-size$typography-label-size-large输入框文字字号
--wot-input-number-border-color$border-main主题边框颜色
--wot-input-number-disabled-opacity$opacity-disabled禁用态透明度
--wot-input-number-action-primary-bg$primary-6primary 主题主按钮背景色
--wot-input-number-action-primary-color$icon-whiteprimary 主题主按钮颜色
--wot-input-number-action-primary-sub-color$primary-6primary 主题次按钮颜色

Source Code

Documentation
Component

Released under the MIT License.

Released under the MIT License.