Stepper
Combine a steps bar, content panels and navigation buttons. Each HuiStepperPanel supplies one stage, with validation, disabled stages and optional lazy rendering.
Use Steps alone for order or approval progress. Stepper composes Steps with panels and navigation for multi-step input; its progress bar reuses the same Steps component.
Import
import { HuiStepper, HuiStepperPanel } from '@nscode/handy-ui'
Internal state and controlled updates
Omitting active, including with an update listener only, stores the current step internally from zero. A passed prop, including undefined, remains controlled; undefined displays as zero. Rejected navigation leaves the actual panel, lazy content and reached range unchanged. A true result from next() means validation and the request passed; the parent still controls the actual index. reset() also requests a parent update and preserves inputs.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiStepper, HuiStepperPanel, HuiInput, HuiButton, HuiSpace } from '@nscode/handy-ui'
const q1Redraw = ref(0)
const q1Last = ref('No request')
const q1Model = ref(0)
const q1Bound = ref<InstanceType<typeof HuiStepper>>()
</script>
<template>
<div class="stepper-q1-demo">
<HuiSpace
><HuiButton class="q1-redraw" @click="q1Redraw++">Parent redraw {{ q1Redraw }}</HuiButton
><HuiButton class="q1-reset" @click="q1Bound?.reset()"
>Reset bound stepper</HuiButton
></HuiSpace
><HuiSpace direction="vertical" fill>
<div>
<p>Omitted prop: internal state</p>
<div class="q1-local">
<HuiStepper lazy
><HuiStepperPanel title="First"
><HuiInput placeholder="Retained input" /></HuiStepperPanel
><HuiStepperPanel title="Second">Second content</HuiStepperPanel
><HuiStepperPanel title="Third">Third content</HuiStepperPanel></HuiStepper
>
</div>
</div>
<div>
<p>Update listener only: internal state</p>
<div class="q1-listener">
<HuiStepper lazy @update:active="q1Last = String($event)"
><HuiStepperPanel title="First"
><HuiInput placeholder="Retained input" /></HuiStepperPanel
><HuiStepperPanel title="Second">Second content</HuiStepperPanel
><HuiStepperPanel title="Third">Third content</HuiStepperPanel></HuiStepper
>
</div>
</div>
<div>
<p>Explicit undefined: controlled</p>
<div class="q1-empty">
<HuiStepper lazy :active="undefined"
><HuiStepperPanel title="First"
><HuiInput placeholder="Retained input" /></HuiStepperPanel
><HuiStepperPanel title="Second">Second content</HuiStepperPanel
><HuiStepperPanel title="Third">Third content</HuiStepperPanel></HuiStepper
>
</div>
</div>
<div>
<p>Fixed controlled value: parent rejects</p>
<div class="q1-fixed">
<HuiStepper lazy :active="1" @update:active="q1Last = String($event)"
><HuiStepperPanel title="First"
><HuiInput placeholder="Retained input" /></HuiStepperPanel
><HuiStepperPanel title="Second">Second content</HuiStepperPanel
><HuiStepperPanel title="Third">Third content</HuiStepperPanel></HuiStepper
>
</div>
</div>
<div>
<p>Two-way binding</p>
<div class="q1-bound">
<HuiStepper lazy ref="q1Bound" v-model:active="q1Model"
><HuiStepperPanel title="First"
><HuiInput placeholder="Retained input" /></HuiStepperPanel
><HuiStepperPanel title="Second">Second content</HuiStepperPanel
><HuiStepperPanel title="Third">Third content</HuiStepperPanel></HuiStepper
>
</div>
</div>
<p class="q1-notification">
Bound value: {{ q1Model }}; latest request: {{ q1Last }}
</p></HuiSpace
>
</div>
</template>
Basic usage
Without active, the component manages its own index. By default, the steps bar only allows returning to stages already reached. Use Next to unlock another stage. The last enabled stage displays Finish and emits finish after validation succeeds.
<script setup lang="ts">
import { HuiInput, HuiMessage, HuiStepper, HuiStepperPanel } from '@nscode/handy-ui'
const finish = () => HuiMessage.success('Process completed')
</script>
<template>
<HuiStepper @finish="finish">
<HuiStepperPanel title="Information" description="Enter your details">
<HuiInput placeholder="Your name is preserved when switching stages" />
</HuiStepperPanel>
<HuiStepperPanel title="Attachments" description="Prepare your documents">
<p>Check that all required documents are ready.</p>
</HuiStepperPanel>
<HuiStepperPanel title="Submit" description="Review the result">
<p>Click Finish after reviewing your information.</p>
</HuiStepperPanel>
</HuiStepper>
</template>
Two-way binding and events
v-model:active uses zero-based indices. Navigation emits update:active followed by change(newIndex, { previous: previousIndex }). Assigning active externally bypasses before-next and emits neither event, which is useful when restoring a draft.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiButton, HuiSpace, HuiStepper, HuiStepperPanel } from '@nscode/handy-ui'
const active = ref(0)
const event = ref('No selection yet')
const onChange = (next: number, { previous }: { previous: number }) => {
event.value = `change: ${previous} → ${next}`
}
</script>
<template>
<HuiSpace direction="vertical" fill>
<HuiStepper v-model:active="active" @change="onChange" @finish="event = 'finish: completed'">
<HuiStepperPanel title="Details"><p>Enter your details.</p></HuiStepperPanel>
<HuiStepperPanel title="Review"><p>Review the information.</p></HuiStepperPanel>
<HuiStepperPanel title="Submit"><p>Confirm and finish.</p></HuiStepperPanel>
</HuiStepper>
<HuiSpace>
<HuiButton @click="active = 2">Restore stage 3 from a draft</HuiButton>
<span>Current index: {{ active }}; {{ event }}</span>
</HuiSpace>
</HuiSpace>
</template>
Form validation
before-next receives the current index. Returning false, throwing or rejecting a Promise keeps the current stage. Returning true or nothing allows navigation. Only forward navigation and Finish validate the stage; returning to an earlier stage does not.
<script setup lang="ts">
import { ref } from 'vue'
import {
HuiForm,
HuiFormItem,
HuiInput,
HuiMessage,
HuiStepper,
HuiStepperPanel
} from '@nscode/handy-ui'
const formRef = ref<InstanceType<typeof HuiForm>>()
const model = ref({ name: '', phone: '' })
const rules = {
name: [{ required: true, message: 'Enter your name', trigger: 'blur' }],
phone: [{ required: true, message: 'Enter your phone number', trigger: 'blur' }]
}
const validate = async (index: number) => {
if (index === 0) return (await formRef.value!.validate()).valid
}
</script>
<template>
<HuiStepper :before-next="validate" @finish="HuiMessage.success('Validation passed')">
<HuiStepperPanel title="Information">
<HuiForm ref="formRef" :model="model" :rules="rules" label-width="110px">
<HuiFormItem label="Name" prop="name"><HuiInput v-model="model.name" /></HuiFormItem>
<HuiFormItem label="Phone" prop="phone"><HuiInput v-model="model.phone" /></HuiFormItem>
</HuiForm>
</HuiStepperPanel>
<HuiStepperPanel title="Review">
<p>Name: {{ model.name }}; phone: {{ model.phone }}</p>
</HuiStepperPanel>
</HuiStepper>
</template>
Asynchronous validation
A returned Promise puts the Next or Finish button into its loading state. Navigation buttons, the steps bar and navigation methods stay locked until it settles. Repeated Next actions only invoke validation once.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiSpace, HuiStepper, HuiStepperPanel, HuiSwitch } from '@nscode/handy-ui'
const allowed = ref(true)
const result = ref('Waiting for an action')
const validate = async (index: number) => {
result.value = `Validating stage ${index + 1}`
await new Promise((resolve) => setTimeout(resolve, 1000))
result.value = allowed.value ? 'Validation passed' : 'Validation failed; staying here'
return allowed.value
}
</script>
<template>
<HuiSpace direction="vertical" fill>
<HuiSpace><span>Allow validation</span><HuiSwitch v-model="allowed" /></HuiSpace>
<HuiStepper :before-next="validate" @finish="result = 'All done'">
<HuiStepperPanel title="Details"><p>Click Next and wait one second.</p></HuiStepperPanel>
<HuiStepperPanel title="Submit"
><p>Finish also validates the current stage.</p></HuiStepperPanel
>
</HuiStepper>
<span>{{ result }}</span>
</HuiSpace>
</template>
An external active change, removing, disabling or repositioning the current panel, reset(), unmounting or KeepAlive deactivation cancels pending navigation. Changing other panels does not cancel Next: after validation, it finds the next enabled panel from the latest list. goTo(index) additionally requires its original target to remain enabled at that index. An old Promise cannot navigate a new process or unlock a newer request. Cancel the validation request itself in your application if needed.
Exclusive sessions and cancelled results
Only one forward operation runs at a time, including form validation inside beforeNext. Returning undefined allows navigation; false, throw and rejection block it. Errors produce a development diagnostic labeled Stepper.beforeNext. Reset, external active changes and invalidated panels make pending results stale without stopping the business request itself. Parent updates win when they arrive before the navigation is applied.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiButton, HuiSpace, HuiStepper, HuiStepperPanel } from '@nscode/handy-ui'
import type { StepperExpose } from '@nscode/handy-ui'
interface WaitingStep {
id: number
index: number
resolve: (value: boolean | void) => void
}
const wizard = ref<StepperExpose>()
const active = ref(0)
const pending = ref<WaitingStep[]>([])
const outcome = ref('No request yet')
let seed = 0
const beforeNext = (index: number) =>
new Promise<boolean | void>((resolve) => {
pending.value.push({ id: ++seed, index, resolve })
})
const start = async () => {
outcome.value = 'Navigation result: ' + (await wizard.value!.next())
}
const release = (request: WaitingStep, allowed: boolean) => {
pending.value = pending.value.filter((item) => item.id !== request.id)
request.resolve(allowed ? undefined : false)
}
</script>
<template>
<HuiSpace direction="vertical" fill class="stepper-guard-demo">
<HuiSpace wrap>
<HuiButton @click="start">Request next</HuiButton>
<HuiButton @click="wizard?.reset()">Reset and invalidate waiting results</HuiButton>
<HuiButton @click="active = 2">Set third step externally</HuiButton>
</HuiSpace>
<HuiStepper ref="wizard" v-model:active="active" :before-next="beforeNext">
<HuiStepperPanel title="Details"><p>Details</p></HuiStepperPanel>
<HuiStepperPanel title="Review"><p>Review</p></HuiStepperPanel>
<HuiStepperPanel title="Submit"><p>Submit</p></HuiStepperPanel>
</HuiStepper>
<HuiSpace v-for="request in pending" :key="request.id" wrap>
<span>#{{ request.id }} / {{ request.index }}</span>
<HuiButton @click="release(request, true)">Allow (undefined)</HuiButton>
<HuiButton @click="release(request, false)">Block (false)</HuiButton>
</HuiSpace>
<span class="stepper-guard-result">Current step: {{ active }}; {{ outcome }}</span>
<span
>Indices start at 0. Request next, reset, then allow the old request: its result cannot
navigate.</span
>
</HuiSpace>
</template>
Conditionally skip stages after validation
before-next can disable a later panel based on business validation. The current action validates once and proceeds to the latest next enabled stage, including when the callback is asynchronous. Toggle the switches below to skip Additional documents and optionally wait for a simulated request.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiButton, HuiSpace, HuiStepper, HuiStepperPanel, HuiSwitch } from '@nscode/handy-ui'
const stepperRef = ref<InstanceType<typeof HuiStepper>>()
const skip = ref(true)
const asynchronous = ref(false)
const disabled = ref(false)
const calls = ref(0)
const validate = (index: number) => {
calls.value++
const apply = () => {
if (index === 0) disabled.value = skip.value
return true
}
return asynchronous.value
? new Promise<boolean>((resolve) => setTimeout(() => resolve(apply()), 500))
: apply()
}
</script>
<template>
<HuiSpace direction="vertical" fill>
<HuiSpace wrap
><span>Skip additional documents</span><HuiSwitch v-model="skip" /><span
>Wait for a request</span
><HuiSwitch v-model="asynchronous" /><HuiButton @click="stepperRef?.reset()"
>Reset progress and retry</HuiButton
></HuiSpace
>
<HuiStepper ref="stepperRef" :before-next="validate">
<HuiStepperPanel title="Information"
><p>Click Next once to choose the appropriate stage.</p></HuiStepperPanel
>
<HuiStepperPanel title="Additional documents" :disabled="disabled"
><p>Complete only when required.</p></HuiStepperPanel
>
<HuiStepperPanel title="Submit"
><p>Unnecessary stages were skipped after validation.</p></HuiStepperPanel
>
</HuiStepper>
<span>{{ calls }} validation calls</span>
</HuiSpace>
</template>
Nonlinear navigation and disabled stages
:linear="false" allows selecting any enabled stage directly. Forward navigation still validates only the current stage. Previous and Next skip disabled stages. When the final panel is disabled, the preceding enabled panel becomes the Finish stage.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiSpace, HuiStepper, HuiStepperPanel, HuiSwitch } from '@nscode/handy-ui'
const disabled = ref(true)
const message = ref('You can select stage 3 directly')
const validate = (index: number) => {
message.value = `Validated stage ${index + 1} before moving forward`
return true
}
</script>
<template>
<HuiSpace direction="vertical" fill>
<HuiSpace><span>Disable the middle stage</span><HuiSwitch v-model="disabled" /></HuiSpace>
<HuiStepper :linear="false" :before-next="validate" @finish="message = 'Completed'">
<HuiStepperPanel title="Details"><p>Enter your details.</p></HuiStepperPanel>
<HuiStepperPanel title="Optional review" :disabled="disabled"
><p>This stage can be disabled.</p></HuiStepperPanel
>
<HuiStepperPanel title="Submit"><p>Confirm the result.</p></HuiStepperPanel>
</HuiStepper>
<span>{{ message }}</span>
</HuiSpace>
</template>
Direction, alignment and simple style
The default direction="horizontal" places the steps bar above the panels; vertical places it on the left. align-center affects horizontal stages. simple uses the compact steps style.
<script setup lang="ts">
import { HuiSpace, HuiStepper, HuiStepperPanel } from '@nscode/handy-ui'
</script>
<template>
<HuiSpace direction="vertical" fill size="large">
<div>
<p>horizontal, default alignment</p>
<HuiStepper direction="horizontal">
<HuiStepperPanel title="Details"><p>Default appearance.</p></HuiStepperPanel>
<HuiStepperPanel title="Finish"><p>Confirm and finish.</p></HuiStepperPanel>
</HuiStepper>
</div>
<div>
<p>align-center + simple</p>
<HuiStepper align-center simple>
<HuiStepperPanel title="Details"><p>Centered, compact appearance.</p></HuiStepperPanel>
<HuiStepperPanel title="Finish"><p>Confirm and finish.</p></HuiStepperPanel>
</HuiStepper>
</div>
<div>
<p>vertical</p>
<HuiStepper direction="vertical">
<HuiStepperPanel title="Details" description="Enter information"
><p>The steps bar is on the left.</p></HuiStepperPanel
>
<HuiStepperPanel title="Finish" description="Confirm the result"
><p>Confirm and finish.</p></HuiStepperPanel
>
</HuiStepper>
</div>
</HuiSpace>
</template>
Titles, descriptions, icons and status
A panel's title is its step title and accessible region name. description and icon appear in the steps bar. Icons accept a name or VNode. status overrides the inferred value with wait, process, finish, error or success.
<script setup lang="ts">
import { h } from 'vue'
import { HuiIcon, HuiStepper, HuiStepperPanel } from '@nscode/handy-ui'
const star = h(HuiIcon, { name: 'star' })
</script>
<template>
<HuiStepper :active="2" :linear="false">
<HuiStepperPanel title="Waiting" description="wait" status="wait" icon="user"
><p>Waiting status.</p></HuiStepperPanel
>
<HuiStepperPanel title="In progress" description="process" status="process"
><p>In-progress status.</p></HuiStepperPanel
>
<HuiStepperPanel title="Finished" description="finish" status="finish"
><p>Finished status.</p></HuiStepperPanel
>
<HuiStepperPanel title="Error" description="error" status="error"
><p>The application supplies this error status.</p></HuiStepperPanel
>
<HuiStepperPanel
title="Success"
description="success + VNode icon"
status="success"
:icon="star"
><p>Success status.</p></HuiStepperPanel
>
</HuiStepper>
</template>
Custom button text and actions
The three text props override locale defaults; an empty string is an explicit override. The actions slot replaces the button area and receives the current index, boundary and loading states, and navigation functions. An explicitly provided slot still appears when show-actions is false.
<script setup lang="ts">
import { HuiStepper, HuiStepperPanel } from '@nscode/handy-ui'
</script>
<template>
<HuiStepper
prev-button-text="Edit details"
next-button-text="Save and continue"
finish-button-text="Submit now"
>
<HuiStepperPanel title="Details"><p>Click Save and continue.</p></HuiStepperPanel>
<HuiStepperPanel title="Review"><p>The forward button now says Submit now.</p></HuiStepperPanel>
</HuiStepper>
</template>
<script setup lang="ts">
import { HuiButton, HuiMessage, HuiSpace, HuiStepper, HuiStepperPanel } from '@nscode/handy-ui'
</script>
<template>
<HuiStepper :show-actions="false" @finish="HuiMessage.success('Submitted')">
<HuiStepperPanel title="Details"><p>Custom actions.</p></HuiStepperPanel>
<HuiStepperPanel title="Submit"><p>Confirm and submit.</p></HuiStepperPanel>
<template #actions="{ active, isFirst, isLast, loading, prev, next }">
<HuiSpace>
<span>Stage {{ active + 1 }}</span>
<HuiButton :disabled="loading" @click="HuiMessage.success('Draft saved')"
>Save draft</HuiButton
>
<HuiButton :disabled="isFirst || loading" @click="prev">Back</HuiButton>
<HuiButton type="primary" :loading="loading" @click="next">{{
isLast ? 'Submit' : 'Continue'
}}</HuiButton>
</HuiSpace>
</template>
</HuiStepper>
</template>
Lazy rendering and preserved content
By default, all panels mount immediately and inactive panels are hidden. With lazy, content mounts when first visited, then stays mounted. The timestamp and input values below remain unchanged after returning to a stage.
<script setup lang="ts">
import { defineComponent, h } from 'vue'
import { HuiInput, HuiSpace, HuiStepper, HuiStepperPanel } from '@nscode/handy-ui'
const RenderTime = defineComponent({
setup() {
const time = new Date().toLocaleTimeString()
return () => h('p', `First rendered: ${time}`)
}
})
</script>
<template>
<HuiStepper lazy>
<HuiStepperPanel title="One">
<HuiSpace direction="vertical" fill
><RenderTime /><HuiInput placeholder="Enter text, leave and return"
/></HuiSpace>
</HuiStepperPanel>
<HuiStepperPanel title="Two">
<HuiSpace direction="vertical" fill
><RenderTime /><HuiInput placeholder="Mounted on the first visit"
/></HuiSpace>
</HuiStepperPanel>
<HuiStepperPanel title="Three">
<HuiSpace direction="vertical" fill
><RenderTime />
<p>Return to see preserved state.</p></HuiSpace
>
</HuiStepperPanel>
</HuiStepper>
</template>
Methods and external controls
show-actions="false" hides the built-in buttons. External controls can call methods through a component ref. With the default linear mode, goTo only reaches stages already unlocked; next unlocks new stages. reset() returns to the first enabled stage and resets navigation progress while preserving mounted panel content.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiButton, HuiInput, HuiSpace, HuiStepper, HuiStepperPanel } from '@nscode/handy-ui'
const stepperRef = ref<InstanceType<typeof HuiStepper>>()
const active = ref(0)
const result = ref('Unlock stages with next, then try goTo')
const next = async () => {
result.value = `next: ${await stepperRef.value!.next()}`
}
const jump = async () => {
result.value = `goTo(2): ${await stepperRef.value!.goTo(2)}`
}
</script>
<template>
<HuiSpace direction="vertical" fill>
<HuiStepper
ref="stepperRef"
v-model:active="active"
:show-actions="false"
@finish="result = 'finish: completed'"
>
<HuiStepperPanel title="One"
><HuiInput placeholder="reset preserves this content"
/></HuiStepperPanel>
<HuiStepperPanel title="Two"><p>Second stage.</p></HuiStepperPanel>
<HuiStepperPanel title="Three"><p>Third stage.</p></HuiStepperPanel>
</HuiStepper>
<HuiSpace wrap>
<HuiButton @click="stepperRef?.prev()">prev()</HuiButton>
<HuiButton @click="next">next()</HuiButton>
<HuiButton @click="jump">goTo(2)</HuiButton>
<HuiButton @click="stepperRef?.reset()">reset()</HuiButton>
<span>Current index: {{ active }}; {{ result }}</span>
</HuiSpace>
</HuiSpace>
</template>
HuiStepper Props
| Prop | Type | Default | Description |
|---|---|---|---|
| active / v-model:active | number | undefined | Current index; managed internally when omitted; external assignment bypasses validation Omitted prop starts at zero internally; a passed prop is controlled. |
| linear | boolean | true | Limit the steps bar and goTo to stages already reached |
| beforeNext | (active: number) => boolean | void | Promise<boolean | void> | — | Exclusive validation before advancing or finishing; undefined allows, false/throw/rejection blocks; stale results are ignored |
| direction | 'horizontal' | 'vertical' | 'horizontal' | Steps bar above or to the left |
| alignCenter | boolean | false | Center horizontal stage content |
| simple | boolean | false | Compact steps style |
| lazy | boolean | false | Mount panel content on its first visit, then preserve it |
| showActions | boolean | true | Display built-in buttons; does not hide an explicit actions slot |
| prevButtonText | string | Locale Previous | Previous text; preserves empty strings |
| nextButtonText | string | Locale Next | Next text; preserves empty strings |
| finishButtonText | string | Locale Finish | Finish text; preserves empty strings |
HuiStepperPanel Props
| Prop | Type | Default | Description |
|---|---|---|---|
| title | string | '' | Step title and accessible panel name; recommended |
| description | string | '' | Stage description |
| icon | string | VNode | — | Icon name or VNode |
| status | StepsStatus | Inferred from active | wait, process, finish, error or success |
| disabled | boolean | false | Disable selection; previous and next navigation skip this panel |
Events
| Event | Parameters | Description |
|---|---|---|
| update:active | (active: number) | Internal navigation changed the current stage |
| change | (active: number, context: StepperChangeContext) | Reports the new index and context.previous after update:active |
| finish | () | Validation passed at the final enabled stage |
Slots
| Component | Slot | Scope | Description |
|---|---|---|---|
| HuiStepper | default | — | HuiStepperPanel components |
| HuiStepper | actions | StepperActionsSlotProps | Custom actions |
| HuiStepperPanel | default | — | Panel content |
Methods and exposed properties
| Name | Type | Description |
|---|---|---|
| next | () => Promise<boolean> | Advance or finish; true when validation passes and navigation remains valid |
| prev | () => void | Return to the previous enabled stage without validation |
| goTo | (index: number) => Promise<boolean> | Select an enabled stage; validates forward navigation and respects linear progress |
| reset | () => void | Cancel pending navigation, return to the first enabled stage and reset progress; preserve content |
| active | number | Read-only current internal index |
Types
import type {
StepperProps,
StepperEmits,
StepperChangeContext,
StepperPanelProps,
StepperActionsSlotProps,
StepperExpose,
StepperPanelInstance,
StepperContext
} from '@nscode/handy-ui'
interface StepperChangeContext {
previous: number
}
interface StepperActionsSlotProps {
active: number
isFirst: boolean
isLast: boolean
loading: boolean
prev: () => void
next: () => Promise<boolean>
}
STEPPER_INJECTION_KEY is also exported for custom panels that register with the stepper.