Skip to content

NumberStep Stepper Component

This component is generally used in shopping mall scenarios for selecting item quantities

📌 Platform Differences

APP(vue)H5WeChat Mini ProgramAlipay Mini Program

Notes

Notes

This input field only accepts integers greater than or equal to 0

🏯 Basic Usage Examples

html
<!-- Global usage -->
<hy-number-step v-model="value"></hy-number-step>
ts
import { vue } from 'vue';

const value = ref(12);

Step Setting

  • Set the value to change each time the increase or decrease button is clicked via the step attribute. The default is 1. In the example below, each click will add or subtract 2
html
<template>
    <hy-number-step v-model="value" :step="2"></hy-number-step>
</template>

Limiting the Input Range

  • min - minimum value
  • max - maximum value
html
<template>
    <hy-number-step v-model="value" :min="1" :max="100"></hy-number-step>
</template>

Restricting Input to Integers Only

  • Restrict the input type via integer
html
<template>
    <hy-number-step v-model="value" integer></hy-number-step>
</template>

Disabled

  • Disable the stepper via disabled. When disabled, the plus/minus buttons cannot be clicked and the input value cannot be modified
  • Disable the input field via disabledInput
  • Disable the increase button via disablePlus
  • Disable the decrease button via disableMinus
  • Disable the long-press event via longPress
html
<!-- Disable the input field by setting the `disabled` parameter; when disabled, the plus/minus buttons cannot be clicked and the input value cannot be modified -->
<hy-number-step :disabled="true"></hy-number-step>

<!-- Disable the input field -->
<hy-number-step :disabledInput="true"></hy-number-step>

<!-- Disable the increase button -->
<hy-number-step :disablePlus="true"></hy-number-step>

<!-- Disable the decrease button -->
<hy-number-step :disableMinus="true"></hy-number-step>

<!-- Disable long-press -->
<hy-number-step :longPress="false"></hy-number-step>

Color and Size

  • Set the button size via the button-size parameter
  • Set the style of the plus/minus button icons via the icon-style parameter
html
<template>
    <hy-number-step
        v-model="value"
        button-size="36"
        color="#ffffff"
        bgColor="#2979ff"
        iconStyle="color: #fff"
    ></hy-number-step>
</template>

Hiding the Minus Sign

html
<hy-number-step
    v-model="item.quantity"
    :min="0"
    :miniMode="true"
    input-bg-color="transparent"
    :plusIcon="{ color: '#ffffff' }"
    button-radius="50%"
></hy-number-step>
scss
.hidden {
    :deep(.hy-number-box__plus) {
        background-color: red;
    }

    :deep(.hy-number-box__minus) {
        border: $hy-border-line;
        background-color: transparent;
    }
}

Custom Slots

html
<template>
    <hy-number-step v-model="value">
        <template #minus>
            <view class="minus">
                <up-icon name="minus" size="12"></up-icon>
            </view>
        </template>
        <template #input>
            <text style="width: 50px;text-align: center;" class="input">{{value}}</text>
        </template>
        <template #plus>
            <view class="plus">
                <up-icon name="plus" color="#FFFFFF" size="12"></up-icon>
            </view>
        </template>
    </hy-number-step>
</template>
ts
import { ref } from 'vue';

// Create reactive data
const value = ref(1);
scss
.minus {
    width: 22px;
    height: 22px;
    border: 1px solid black;
    box-sizing: border-box;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
}

.input {
    padding: 0 10px;
}

.plus {
    width: 22px;
    height: 22px;
    background-color: #ff0000;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
}

API

NumberStep Props

ParameterDescriptionTypeDefault
v-modelValue used for two-way binding; set to the default min value (minimum) on initializationnumber-
minMinimum value the user can enternumber1
maxMaximum value the user can enternumberNumber.MAX_SAFE_INTEGER
stepStep size, the value added or subtracted each time; supports decimal valuesnumber1
integerWhether only positive integers can be enteredbooleanfalse
disabledWhether to disable operations, including the input field and plus/minus buttonsbooleanfalse
disabledInputWhether to disable the input fieldbooleanfalse
asyncChangeWhether to enable asynchronous changes; when enabled, the input value must be controlled manuallybooleanfalse
inputWidthInput field width; numeric values default to pxstring|number35
showMinusWhether to show the decrease buttonbooleantrue
showPlusWhether to show the increase buttonbooleantrue
decimalLengthNumber of decimal places to displaystring|number-
longPressWhether long-pressing is allowed to increment/decrementbooleantrue
colorColor of the input field text and plus/minus button iconsstring-
buttonWidthButton width; numeric values default to pxstring|number30
buttonSizeButton height; numeric values default to px; the input field height matches this valuestring|number30
buttonRadiusButton border radius; numeric values default to pxstring|number-
bgColorBackground color of the input field and buttonsstring-
inputBgColorIndependent background color of the input fieldstring-
cursorSpacingSpecifies the distance between the cursor and the keyboard to prevent the keyboard from covering the input field; numeric values default to pxstring|number100
disablePlusWhether to disable the increase buttonbooleanfalse
disableMinusWhether to disable the decrease buttonbooleanfalse
minusIconCollection of minus button icon properties; see Icon APIHyIconProps-
plusIconCollection of plus button icon properties; see Icon APIHyIconProps-
miniModeMini mode, commonly used for food delivery; only the + button is displayed when the value is 0booleanfalse
customStyleCustom external styles to be appliedCSSProperties-
customClassCustom external class namestring-

Events

Event NameDescriptionCallback Parameters
focusTriggered when the input field gains focusvalue: numeric value
blurTriggered when the input field loses focusvalue: numeric value
changeTriggered when the input field content changesvalue: numeric value
overLimitTriggered when the range threshold is exceededtype: minus|plus
plusTriggered when the increase button is clickedvalue: numeric value
minusTriggered when the decrease button is clickedvalue: numeric value

Slots

Slot NameDescriptionValue Received
minusDecrease button-
inputInput fieldrecord
plusIncrease button-
03:29