# Stepper

Shows where the user is in a multi-step flow such as checkout or onboarding, and lets them move between steps. The stepper only renders the progress; your page renders the active step.

- Package: [@vigdx/ui](https://www.npmjs.com/package/@vigdx/ui)
- Selectors: `vig-stepper`
- Source: [libs/ui/src/lib/organisms/stepper/stepper.ts](https://github.com/bakyurekk/vigdx/blob/main/libs/ui/src/lib/organisms/stepper/stepper.ts)

```typescript title="Import"
import { Stepper } from '@vigdx/ui/stepper';
```

## Basic

Steps are data: a `label` and an optional `description`. Bind `[(activeIndex)]` and render the panel for it yourself; a template reference gives access to `next()` and `previous()` for your own buttons. Every step is clickable.

```typescript title="stepper-basic.ts"
import { ChangeDetectionStrategy, Component, signal } from '@angular/core';
import { Button } from '@vigdx/ui/button';
import { Stepper, type StepperStep } from '@vigdx/ui/stepper';

@Component({
  selector: 'app-stepper-basic',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [Button, Stepper],
  template: `
    <vig-stepper #stepper ariaLabel="Checkout" [steps]="steps" [(activeIndex)]="active" />

    <div class="rounded-card border border-border p-4 text-sm">
      @switch (active()) {
        @case (0) {
          <p>Enter the email address for your order confirmation.</p>
        }
        @case (1) {
          <p>Where should we deliver your order?</p>
        }
        @case (2) {
          <p>Choose a card or pay by bank transfer.</p>
        }
        @default {
          <p>Check your order and place it.</p>
        }
      }
    </div>

    <div class="flex justify-between gap-2">
      <vig-button
        label="Back"
        variant="secondary"
        [disabled]="active() === 0"
        (click)="stepper.previous()"
      />
      <vig-button
        label="Next"
        [disabled]="active() === steps.length - 1"
        (click)="stepper.next()"
      />
    </div>
  `,
})
export class StepperBasicDemo {
  protected readonly steps: StepperStep[] = [
    { label: 'Account', description: 'Email address' },
    { label: 'Shipping', description: 'Delivery address' },
    { label: 'Payment', description: 'Card or transfer' },
    { label: 'Review' },
  ];
  protected readonly active = signal(0);
}
```

## Linear

With `linear` the user cannot click past the first incomplete step. Without `completedSteps`, every step before `activeIndex` counts as done; pass it to track completion yourself, e.g. once a step's form is valid. `next()` is not blocked by `linear`.

```typescript title="stepper-linear.ts"
import { ChangeDetectionStrategy, Component, signal } from '@angular/core';
import { Button } from '@vigdx/ui/button';
import { Stepper, type StepperStep } from '@vigdx/ui/stepper';

@Component({
  selector: 'app-stepper-linear',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [Button, Stepper],
  template: `
    <vig-stepper
      #stepper
      ariaLabel="Account setup"
      [steps]="steps"
      [linear]="true"
      [completedSteps]="completed()"
      [(activeIndex)]="active"
    />

    <div class="flex flex-wrap items-center justify-between gap-2">
      <vig-button
        label="Reset"
        variant="secondary"
        appearance="text"
        (click)="completed.set([]); active.set(0)"
      />
      <vig-button
        [label]="active() === steps.length - 1 ? 'Finish' : 'Complete step'"
        [disabled]="completed().includes(active())"
        (click)="complete(stepper)"
      />
    </div>
  `,
})
export class StepperLinearDemo {
  protected readonly steps: StepperStep[] = [
    { label: 'Profile' },
    { label: 'Team' },
    { label: 'Billing' },
    { label: 'Done' },
  ];
  protected readonly active = signal(0);
  protected readonly completed = signal<number[]>([]);

  protected complete(stepper: Stepper): void {
    this.completed.update((done) => [...done, this.active()]);
    stepper.next();
  }
}
```

## Vertical

`orientation="vertical"` stacks the steps, which suits narrow layouts and timelines. Here the stepper only displays progress.

```typescript title="stepper-vertical.ts"
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { Stepper, type StepperStep } from '@vigdx/ui/stepper';

@Component({
  selector: 'app-stepper-vertical',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [Stepper],
  template: `
    <vig-stepper
      ariaLabel="Shipment progress"
      orientation="vertical"
      [steps]="steps"
      [activeIndex]="2"
    />
  `,
})
export class StepperVerticalDemo {
  protected readonly steps: StepperStep[] = [
    { label: 'Order placed', description: 'Monday, 09:12' },
    { label: 'Packed', description: 'Tuesday, 14:40' },
    { label: 'In transit', description: 'Expected Thursday' },
    { label: 'Delivered' },
  ];
}
```

## Icons, errors and disabled steps

`icon` replaces the step number with a registered icon, `error` flags a step that needs attention, and `disabled` steps cannot be visited.

```typescript title="stepper-states.ts"
import { ChangeDetectionStrategy, Component, signal } from '@angular/core';
import { Stepper, type StepperStep } from '@vigdx/ui/stepper';

@Component({
  selector: 'app-stepper-states',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [Stepper],
  template: ` <vig-stepper ariaLabel="Import data" [steps]="steps" [(activeIndex)]="active" /> `,
})
export class StepperStatesDemo {
  protected readonly steps: StepperStep[] = [
    { label: 'Upload', icon: 'upload' },
    { label: 'Map columns', error: true, description: '2 columns unmapped' },
    { label: 'Schedule', icon: 'calendar' },
    { label: 'Notify team', description: 'Requires a paid plan', disabled: true },
  ];
  protected readonly active = signal(2);
}
```

## Styling hooks

Internal elements carry a stable `data-part` and the component's `data-scope`; both are public API, so removing one is a breaking change. Select a part by both, e.g. `[data-scope="stepper"][data-part="list"] { … }`: the pair stays within this component when kit components nest, and also reaches parts in overlay panels, which render outside the host. State is exposed through `aria-*` and, where listed, a `data-state`; literal values are checked by the API gate, values computed from the component's state follow its documented types. Other `data-*` attributes listed below (such as `data-opening` while an overlay animates) are API too. See [Customizing](https://vigdx.com/docs/theming.md#customizing).

Scope: `[data-scope="stepper"]`

| Part | Element | data-state |
| --- | --- | --- |
| `list` | The `<ol>` of steps. |   |
| `step` | One step `<li>`. | `active, complete, error, upcoming, unreachable` |
| `control` | The step button (`aria-current="step"`). |   |
| `marker` | The number, check or icon circle. |   |
| `label` | The step label. |   |
| `status` | The visually hidden state read after the label (", Completed"). |   |
| `description` | The step description. |   |
| `connector` | The line to the next step. |   |

## Accessibility

- Renders a `<nav>` landmark named by `ariaLabel` around an ordered list of step buttons, so the step count and position are announced.
- The current step carries `aria-current="step"`; steps that cannot be reached (disabled, or past the first incomplete step when `linear`) are `aria-disabled` but stay focusable so their label can still be read.
- Completed and failed steps append a visually hidden status, overridable with `completedLabel` and `errorLabel` for i18n.
- The stepper does not move focus when the step changes. When your Next button swaps the panel, move focus to the new step's heading or first field.

## API

### Stepper

Selector: `vig-stepper` · Kind: component

Progress indicator for a multi-step flow. Steps are data; the consumer renders the panel for `activeIndex`. Each step is a button in an ordered list: the current one carries `aria-current="step"`, steps that cannot be reached are `aria-disabled`. With `linear`, the user cannot jump past the first incomplete step.

#### Inputs

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `activeIndex` (model) | `number` | `0` | Index of the current step; two-way bindable with `[(activeIndex)]`. |
| `ariaLabel` | `string \| undefined` | `undefined` | — |
| `completedLabel` | `string \| undefined` | `undefined` | — |
| `completedSteps` | `readonly number[] \| undefined` | `undefined` | Indices of completed steps. When omitted, every step before `activeIndex` counts as completed. |
| `errorLabel` | `string \| undefined` | `undefined` | — |
| `linear` | `boolean` | `false` | Steps can only be visited up to the first incomplete one. |
| `orientation` | `StepperOrientation` | `'horizontal'` | Layout of the steps. `horizontal` falls back to the vertical layout when the stepper is narrower than 36rem. |
| `steps` | `readonly StepperStep[]` | `[]` | — |

#### Outputs

| Name | Payload | Description |
| --- | --- | --- |
| `activeIndexChange` | `number` | Index of the current step; two-way bindable with `[(activeIndex)]`. |

#### Methods

| Signature | Description |
| --- | --- |
| `isReachable(index: number): boolean` | — |
| `next(): void` | Advances to the next enabled step. Meant for the flow's own "Next" button, called once the current step is valid, so `linear` does not block it. |
| `previous(): void` | Goes back to the previous enabled step. |
| `select(index: number): void` | Activates a step when it is reachable. |
