Skip to content

NumberStep Stepper Component ​

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

📌 Platform Differences ​

APP(vue)H5WeChat Mini ProgramAlipay Mini Program
✔✔✔✔

Notes ​

Note

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

🏯 Basic Usage Example ​

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

const value = ref(12);

Step Setting ​

  • Use the step property to set the value that changes each time the plus or minus button is clicked. Defaults to 1. In the example below, 2 is added or subtracted each time
html
<template>
    <hy-number-step v-model="value" :step="2"></hy-number-step>
</template>

Limit Input Range ​

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

Restrict Input to Integers Only ​

  • Use integer to restrict the input type
html
<template>
    <hy-number-step v-model="value" integer></hy-number-step>
</template>

Disable ​

  • Use disabled to disable the stepper; when disabled, the plus/minus buttons cannot be clicked and the input value cannot be modified
  • Use disabledInput to disable the input box
  • Use disablePlus to disable the plus button
  • Use disableMinus to disable the minus button
  • Use longPress to disable the long-press event
html
<!-- Disable the input box 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 box -->
<hy-number-step :disabledInput="true"></hy-number-step>

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

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

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

Color and Size ​

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

Hide 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 Value
v-modelThe value used for two-way binding; on initialization, it is set to the default min value (minimum)number-
minThe minimum value the user can enternumber1
maxThe maximum value the user can enternumberNumber.MAX_SAFE_INTEGER
stepStep size, the value added or subtracted each time; decimal values are supported if needednumber1
integerWhether only positive integers can be enteredbooleanfalse
disabledWhether to disable operations, including the input box and plus/minus buttonsbooleanfalse
disabledInputWhether to disable the input boxbooleanfalse
asyncChangeWhether to enable asynchronous changes; when enabled, the input value must be controlled manuallybooleanfalse
inputWidthInput box width; numerical values default to pxstring|number35
showMinusWhether to show the minus buttonbooleantrue
showPlusWhether to show the plus buttonbooleantrue
decimalLengthNumber of decimal places to displaystring|number-
longPressWhether long-press is allowed for plus/minus operationsbooleantrue
colorColor of the input box text and plus/minus button iconsstring-
buttonWidthButton width; numerical values default to pxstring|number30
buttonSizeButton height; numerical values default to px, and the input box height stays consistent with this valuestring|number30
buttonRadiusButton border radius; numerical values default to pxstring|number-
bgColorBackground color of the input box and buttonsstring-
inputBgColorIndependent background color of the input boxstring-
cursorSpacingSpecifies the distance between the cursor and the keyboard to prevent the keyboard from covering the input box; numerical values default to pxstring|number100
disablePlusWhether to disable the plus buttonbooleanfalse
disableMinusWhether to disable the minus buttonbooleanfalse
minusIconCollection of minus button icon properties; see Icon API for detailsHyIconProps-
plusIconCollection of plus button icon properties; see Icon API for detailsHyIconProps-
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 box gains focusvalue: number
blurTriggered when the input box loses focusvalue: number
changeTriggered when the input box content changesvalue: number
overLimitTriggered when the range threshold is exceededtype: minus|plus
plusTriggered when the plus button is clickedvalue: number
minusTriggered when the minus button is clickedvalue: number

Slots ​

Slot NameDescriptionAccepted Value
minusMinus button-
inputInput boxrecord
plusPlus button-

CSS Variables ​

Variable NameDescriptionDefault Value
--hy-number-step-btn-widthPlus/minus button width35px
--hy-number-step-radiusBorder radius4px
--hy-number-step-font-sizeFont size15px
--hy-number-step-input-marginInput box outer margin0 2px
--hy-number-step-input-colorInput text colorFollows --hy-text-color
--hy-number-step-disabled-colorDisabled text colorFollows --hy-text-color--disabled
12:33
battery