Liking cljdoc? Tell your friends :D

x-stepper

A stateless stepper / wizard-progress component that visualises a sequence of named steps, marking each as completed, current, or upcoming. Clicking a non-current step fires x-stepper-change and — unless cancelled — advances or retreats to that step.

Tag

<x-stepper steps="3" current="0"></x-stepper>

Attributes

AttributeTypeDefaultDescription
stepsJSON array string or integer string"[]"Step definitions. An integer string (e.g. "3") auto-generates Step 1 / Step 2 / Step 3. A JSON array provides explicit labels and optional descriptions: '[{"label":"Account","description":"Create your account"}]'.
currentnumber string"0"0-based index of the active step. Clamped to [0, steps.length − 1].
orientation"horizontal" | "vertical""horizontal"Layout direction of the step track.
size"sm" | "md" | "lg""md"Visual scale of the indicator circles and labels.
disabledpresenceabsentDisables all click interactions.

steps format — JSON array

[
  { "label": "Account",  "description": "Create your account" },
  { "label": "Profile",  "description": "Tell us about yourself" },
  { "label": "Confirm" }
]

description is optional. Steps with no description hide the description element.

Properties

All attributes are reflected as JS properties.

PropertyJS typeNotes
stepsstringGet/set the steps attribute value
currentnumberReturns parsed integer; sets current attribute
orientationstringReturns normalised value ("horizontal" or "vertical")
sizestringReturns normalised value ("sm", "md", or "lg")
disabledbooleanReflects presence attribute

Events

x-stepper-change

Fired when the user clicks a step that is not the current step.

PropertyTypeDescription
detail.fromnumber0-based index of the step the user left
detail.tonumber0-based index of the step the user clicked
cancelabletrueCall event.preventDefault() to prevent the current attribute from updating
el.addEventListener('x-stepper-change', (e) => {
  console.log(`Moving from step ${e.detail.from} to ${e.detail.to}`);
  // Optionally cancel:
  // e.preventDefault();
});

Shadow Parts

PartElementDescription
containerdivThe outer role="list" wrapper
stepdivPer-step wrapper (data-index, data-state attributes)
step-trackdivHolds indicator + connector
step-indicatorbuttonClickable circle/icon for a step
step-numberspanDigit or checkmark inside the indicator
step-connectordivLine segment between indicators; hidden on the last step
step-contentdivHolds label + description
step-labelspanStep label text
step-descriptionspanOptional description text (hidden when empty)

data-state values on [part=step]

ValueMeaning
completeIndex is before current
currentIndex equals current
upcomingIndex is after current

CSS Custom Properties

All properties cascade from :host and can be overridden per-instance.

PropertyDefault (light)Description
--x-stepper-indicator-size2remWidth and height of the circular indicator
--x-stepper-connector-thickness2pxThickness of the connector line
--x-stepper-step-gap0.75remGap between indicator and step content (horizontal: padding-top; vertical: padding-bottom)
--x-stepper-font-size0.875remLabel font size
--x-stepper-label-font-weight500Font weight of the current step label
--x-stepper-desc-font-size0.75remDescription font size
--x-stepper-radius999pxBorder radius of the indicator
--x-stepper-motion120msDuration for background/color transitions
--x-stepper-press-scale0.93Scale applied on :active
--x-stepper-focus-ringrgba(0,0,0,0.55)Focus ring colour
--x-stepper-disabled-opacity0.5Opacity of the host when disabled
--x-stepper-complete-bgrgba(16,140,72,1)Completed indicator background
--x-stepper-complete-color#fffCompleted indicator foreground
--x-stepper-complete-connectorrgba(16,140,72,1)Completed connector colour
--x-stepper-current-bgrgba(0,102,204,1)Current indicator background
--x-stepper-current-color#fffCurrent indicator foreground
--x-stepper-upcoming-bgrgba(0,0,0,0.08)Upcoming indicator background
--x-stepper-upcoming-colorrgba(0,0,0,0.45)Upcoming indicator foreground
--x-stepper-idle-connectorrgba(0,0,0,0.12)Current/upcoming connector colour
--x-stepper-label-done-colorrgba(0,0,0,0.85)Completed step label colour
--x-stepper-label-current-colorrgba(0,0,0,0.85)Current step label colour
--x-stepper-label-upcoming-colorrgba(0,0,0,0.4)Upcoming step label colour
--x-stepper-desc-colorrgba(0,0,0,0.4)Description text colour

Dark-mode overrides are applied automatically via @media (prefers-color-scheme: dark) inside the shadow style.

Accessibility

  • [part=container] has role="list".
  • Each [part=step] has role="listitem".
  • [part=step-indicator] is a <button type="button"> with an aria-label of the form "Step N: Label (current|completed|upcoming)".
  • The current step's indicator has aria-current="step".
  • All indicators are tabindex="0" (or "-1" when disabled), enabling keyboard navigation.
  • The component respects @media (prefers-reduced-motion: reduce) — transitions are disabled.

Theming & Variants

Size

<x-stepper steps="3" size="sm"></x-stepper>
<x-stepper steps="3" size="md"></x-stepper>  <!-- default -->
<x-stepper steps="3" size="lg"></x-stepper>

Orientation

<x-stepper steps="3" orientation="horizontal"></x-stepper>  <!-- default -->
<x-stepper steps="3" orientation="vertical"></x-stepper>

Custom colours

<x-stepper steps="4" current="1"
  style="--x-stepper-current-bg: #7c3aed;
         --x-stepper-complete-bg: #7c3aed;
         --x-stepper-complete-connector: #7c3aed;">
</x-stepper>

Usage Examples

Basic (auto-labelled steps)

<x-stepper steps="4" current="1"></x-stepper>

Named steps with descriptions

<x-stepper
  steps='[
    {"label":"Account","description":"Create your credentials"},
    {"label":"Profile","description":"Tell us about yourself"},
    {"label":"Review"},
    {"label":"Done"}
  ]'
  current="0">
</x-stepper>

Controlled stepper (prevent auto-update)

<x-stepper id="wizard" steps="3" current="0"></x-stepper>
<script>
  const wizard = document.querySelector('#wizard');
  wizard.addEventListener('x-stepper-change', (e) => {
    e.preventDefault();          // stop the default attribute update
    // validate before advancing
    if (canNavigateTo(e.detail.to)) {
      wizard.current = e.detail.to;
    }
  });
</script>

Vertical layout

<x-stepper
  orientation="vertical"
  steps='[{"label":"Install","description":"Run npm install"},
          {"label":"Configure","description":"Edit config file"},
          {"label":"Deploy"}]'
  current="1">
</x-stepper>

Can you improve this documentation?Edit on GitHub

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close