import{o as s,a,y as e}from"./vue-libs.b44bc779.js";const n={class:"van-doc-markdown-body"},d=e(`

Stepper

Intro

The stepper component consists of an increase button, a decrease button and an input box, which are used to input and adjust numbers within a certain range.

Install

Register component globally via app.use, refer to Component Registration for more registration ways.

import { createApp } from 'vue';
import { Stepper } from 'vant';

const app = createApp();
app.use(Stepper);

Usage

Basic Usage

<van-stepper v-model="value" />
import { ref } from 'vue';

export default {
  setup() {
    const value = ref(1);
    return { value };
  },
};

Step

<van-stepper v-model="value" step="2" />

Range

<van-stepper v-model="value" min="5" max="8" />

Integer

<van-stepper v-model="value" integer />

Disabled

<van-stepper v-model="value" disabled />

Disable Input

<van-stepper v-model="value" disable-input />

Decimal Length

<van-stepper v-model="value" step="0.2" :decimal-length="1" />

Custom Size

<van-stepper v-model="value" input-width="40px" button-size="32px" />

Before Change

<van-stepper v-model="value" :before-change="beforeChange" />
import { ref } from 'vue';
import { Toast } from 'vant';

export default {
  setup() {
    const value = ref(1);

    const beforeChange = (value) => {
      Toast.loading({ forbidClick: true });

      return new Promise((resolve) => {
        setTimeout(() => {
          Toast.clear();
          // resolve 'true' or 'false'
          resolve(true);
        }, 500);
      });
    };

    return {
      value,
      beforeChange,
    };
  },
};

Round Theme

<van-stepper v-model="value" theme="round" button-size="22" disable-input />

API

Props

AttributeDescriptionTypeDefault
v-modelCurrent valuenumber | string-
minMin valuenumber | string1
maxMax valuenumber | string-
default-valueDefault value, valid when v-model is emptynumber | string1
stepValue change stepnumber | string1
nameStepper name, usually a unique string or numbernumber | string-
input-widthInput widthnumber | string32px
button-sizeButton sizenumber | string28px
decimal-lengthDecimal lengthnumber | string-
themeTheme, can be set to roundstring-
placeholderInput placeholderstring-
integerWhether to allow only integersbooleanfalse
disabledWhether to disable value changebooleanfalse
disable-plusWhether to disable plus buttonbooleanfalse
disable-minusWhether to disable minus buttonbooleanfalse
disable-inputWhether to disable inputbooleanfalse
before-changeCallback function before changing, return false to prevent change, support return Promise(value: number | string) => boolean | Promise<boolean>false
show-plusWhether to show plus buttonbooleantrue
show-minusWhether to show minus buttonbooleantrue
show-inputWhether to show inputbooleantrue
long-pressWhether to enable the long press gesture, when enabled you can long press the increase and decrease buttonsbooleantrue
allow-emptyWhether to allow the input value to be empty, set to true to allow an empty string to be passed inbooleanfalse

Events

EventDescriptionArguments
changeEmitted when value changedvalue: string, detail: { name: string }
overlimitEmitted when a disabled button is clicked-
plusEmitted when the plus button is clicked-
minusEmitted when the minus button is clicked-
focusEmitted when the input is focusedevent: Event
blurEmitted when the input is blurredevent: Event

Types

The component exports the following type definitions:

import type { StepperTheme, StepperProps } from 'vant';

Theming

CSS Variables

The component provides the following CSS variables, which can be used to customize styles. Please refer to ConfigProvider component.

NameDefault ValueDescription
--van-stepper-background-colorvar(--van-active-color)-
--van-stepper-button-icon-colorvar(--van-text-color)-
--van-stepper-button-disabled-colorvar(--van-background-color)-
--van-stepper-button-disabled-icon-colorvar(--van-gray-5)-
--van-stepper-button-round-theme-colorvar(--van-danger-color)-
--van-stepper-input-width32px-
--van-stepper-input-height28px-
--van-stepper-input-font-sizevar(--van-font-size-md)-
--van-stepper-input-line-heightnormal-
--van-stepper-input-text-colorvar(--van-text-color)-
--van-stepper-input-disabled-text-colorvar(--van-text-color-3)-
--van-stepper-input-disabled-background-colorvar(--van-active-color)-
--van-stepper-border-radiusvar(--van-border-radius-md)-
`,20),l=[d],h={__name:"README",setup(p,{expose:t}){return t({frontmatter:{}}),(o,c)=>(s(),a("div",n,l))}};export{h as default};