Skip to content
LIBRARYNavigationUpdated

Steps ​

Controlled step navigation with a complete registration recipe that preserves visited editors.

Available in alpha.5

Available in Mavis alpha.5.

Web preview
Open example ↗
PropTypeDefaultPurpose
stepsreadonly StepOption[]requiredNonempty ordered steps.
modelValueChoiceValue | nullnullCurrent step; no automatic selection.
labelstringrequiredNavigation name.
loading / disabledbooleanfalsePrevents step requests.
currentLabel / completeLabel / errorLabelstringCurrent / Complete / Needs attentionLocalized state labels.

StepOption is { value, label, disabled?, status?: 'pending' | 'complete' | 'error' }. Typed string/number IDs remain distinct. update:modelValue(value) requests an enabled, different step. Focus alone does not change the step; Tab and each platform's button activation remain normal navigation. Web marks the current action with aria-current="step".

Each step is a numbered mark on a line, with its label below. A complete step shows a check that pops in, a step in error shows an alert that shakes once, and the current step is filled and bumps when it becomes current. Connectors fill up to the current step and empty when the user goes back. While loading, the current mark shows a waiting glyph. Marks and connectors are decorative; the action name keeps the number, label and state.

The host owns panels, routing, backward navigation and permission to advance. The recipe uses Vue KeepAlive with stable step keys, so partial date input and file selection survive returning to a visited panel. It validates before forward navigation, allows going back, registers fields in the parent and reveals the appropriate step before focusing an error. Nothing is saved to a server; finishing is a cancellable local demonstration.

Use an explicit initial step and identical server/client draft for SSR. Do not serialize focus handles, controllers, upload transports or component instances. Router changes and page reload persistence are separate host decisions. The component does not impose a linear wizard or import a router.

vue
<script setup lang="ts">
import { useCatalogLocale } from '../locale'
import { computed, KeepAlive, nextTick, onScopeDispose, reactive, ref, shallowRef } from 'vue'
import type { ChoiceValue, FormError, StepOption } from '@getcortexlabs/mavis-core'
import { useFormController, useFormField } from '@getcortexlabs/mavis-core/vue'
import RegistrationPanel from '../workflows/RegistrationPanel.vue'
import type { RegistrationDraft } from '../workflows/registration'

const { t, locale } = useCatalogLocale(() => props.lang)

const props = withDefaults(defineProps<{ lang?: 'en' | 'pt' }>(), { lang: undefined })

const pt = computed(() => (props.lang ?? locale.value) === 'pt')
const step = ref('details')
let transition = 0
onScopeDispose(() => {
  transition++
})
const completed = ref(false)
const draft = reactive<RegistrationDraft>({
  name: '',
  date: null,
  dateValid: true,
  place: null,
  query: '',
  selected: null,
})
const form = useFormController()
const state = shallowRef(form.state)
onScopeDispose(
  form.subscribe((value) => {
    state.value = value
  }),
)
const panel = ref<InstanceType<typeof RegistrationPanel>>()
for (const [field, section, en, ptLabel] of [
  ['name', 'details', 'Gathering name', 'Nome do encontro'],
  ['date', 'details', 'Gathering date', 'Data do encontro'],
  ['place', 'place', 'City', 'Cidade'],
]) {
  useFormField(form, {
    name: field!,
    label: pt.value ? ptLabel! : en!,
    target: () => panel.value?.getField(field!),
    reveal: async () => {
      transition++
      step.value = section!
      await nextTick()
    },
  })
}
const steps = computed<StepOption[]>(() => [
  {
    value: 'details',
    label: pt.value ? 'Encontro' : 'Gathering',
    status: state.value.errors.some((e) => ['name', 'date'].includes(e.field))
      ? 'error'
      : draft.name.trim() && draft.date && draft.dateValid
        ? 'complete'
        : 'pending',
  },
  {
    value: 'place',
    label: pt.value ? 'Lugar' : 'Place',
    status: state.value.errors.some((e) => e.field === 'place')
      ? 'error'
      : draft.place
        ? 'complete'
        : 'pending',
  },
  {
    value: 'review',
    label: pt.value ? 'Revisão' : 'Review',
    status: completed.value ? 'complete' : 'pending',
  },
])
const errors = (section?: string): FormError[] => {
  const result: FormError[] = []
  if (!section || section === 'details') {
    if (!draft.name.trim())
      result.push({
        field: 'name',
        message: pt.value ? 'Dê um nome ao encontro.' : 'Give your gathering a name.',
      })
    if (!draft.date || !draft.dateValid)
      result.push({
        field: 'date',
        message: pt.value ? 'Informe uma data válida.' : 'Enter a valid date.',
      })
  }
  if ((!section || section === 'place') && !draft.place)
    result.push({ field: 'place', message: pt.value ? 'Escolha uma cidade.' : 'Choose a city.' })
  return result
}
async function changeStep(next: ChoiceValue) {
  if (state.value.validating) return
  const order = ['details', 'place', 'review']
  if (order.indexOf(String(next)) > order.indexOf(step.value)) {
    const current = errors(step.value)
    form.setErrors(current)
    if (current.length) {
      await form.focusFirstError()
      return
    }
  }
  const request = ++transition
  step.value = String(next)
  await nextTick()
  if (request === transition)
    panel.value
      ?.getField(
        step.value === 'details' ? 'name' : step.value === 'place' ? 'place' : 'attachments',
      )
      ?.focus()
}
function edit() {
  completed.value = false
  form.invalidate()
}
async function submit() {
  const result = await form.validate(
    (context) =>
      new Promise((resolve) => {
        const timer = setTimeout(() => resolve(errors()), 450)
        context.onCancel(() => {
          clearTimeout(timer)
          resolve([])
        })
      }),
  )
  if (result === 'invalid') await form.focusFirstError()
  else if (result === 'valid') completed.value = true
}
</script>
<template>
  <m-column gap="lg" id="registration-demo">
    <m-steps
      :modelValue="step"
      :steps="steps"
      :label="t(pt ? 'Etapas do encontro' : 'Gathering steps')"
      :loading="state.validating"
      :currentLabel="pt ? 'Atual' : 'Current'"
      :completeLabel="pt ? 'Completo' : 'Complete'"
      :errorLabel="pt ? 'Revisar' : 'Needs attention'"
      @update:modelValue="changeStep"
    />
    <m-form-errors
      :form="form"
      :title="t(pt ? 'Vamos revisar estes detalhes' : 'Review these details')"
    />
    <KeepAlive>
      <RegistrationPanel
        :key="step"
        ref="panel"
        :step="step"
        :draft="draft"
        :errors="state.errors"
        :lang="props.lang ?? locale"
        @edit="edit"
      />
    </KeepAlive>
    <m-alert
      v-if="completed"
      tone="success"
      :title="t(pt ? 'Encontro preparado' : 'Gathering prepared')"
      :description="
        t(
          pt
            ? 'A demonstração foi concluída. Nenhum cadastro foi enviado.'
            : 'The demonstration is complete. No registration was sent.',
        )
      "
    />
    <m-row gap="sm" wrap>
      <m-button
        v-if="step !== 'details'"
        variant="secondary"
        :disabled="state.validating"
        @click="changeStep(step === 'review' ? 'place' : 'details')"
        >{{ t(pt ? 'Voltar' : 'Back') }}</m-button
      >
      <m-button
        v-if="step !== 'review'"
        :disabled="state.validating"
        @click="changeStep(step === 'details' ? 'place' : 'review')"
        >{{ t(pt ? 'Continuar' : 'Continue') }}</m-button
      >
      <m-button
        :loading="state.validating"
        :variant="step === 'review' ? 'primary' : 'ghost'"
        @click="submit"
        >{{ t(pt ? 'Concluir demonstração' : 'Finish demonstration') }}</m-button
      >
    </m-row>
  </m-column>
</template>

When a step changes status, its previous number or glyph turns away in its original colour. The incoming mark uses the new status colour. The step announces the new status immediately.

Desktop ​

On the desktop each step is a native button named with its number, label and state, and a step only asks for a change when it is enabled and not the current one. While loading, the current step reports busy and the others wait. See Desktop components.

Components for NativeScript and Web. Starting with Vue.