Steps
Two pieces. The indicator is class only and works without a script — it fits a sign-up split across several pages, one step per URL. The wizard uses the same indicator on a single page: moving forward checks the step's fields, and the form stays a single one, submitted whole at the end.
Examples
The indicator on its own, drawn by the template.
Step 3 of 4
is-done on the finished ones and aria-current="step" on the current one. CSS counts the number.
- Cart
- Shipping
- Payment
- Confirmation
Finished steps as links
In a multi-page wizard, a finished step can be an <a> back to it.
- Company
- Partners
- Documents
All done
No aria-current on any of them, and is-done on all.
- Details
- Address
- Payment
How to use
Indicator only, one step per page
An <ol> with each step's name. The template marks the current one with aria-current="step", which
the screen reader announces as "current step", and the previous ones with is-done. There's no script: it's the
path for django-formtools' SessionWizardView, or any wizard where each step is a POST.
<ol class="tuc-steps" aria-label="Sign-up steps">
{% for step in wizard.steps.all %}
<li class="tuc-steps__item{% if forloop.counter0 < wizard.steps.index %} is-done{% endif %}"
{% if step == wizard.steps.current %}aria-current="step"{% endif %}>
<span class="tuc-steps__label">{{ step|title }}</span>
</li>
{% endfor %}
</ol>Wizard on a single page
The indicator, one .tuc-stepper__panel per step — with hidden from the second one on — and the button
bar. Steps and panels match by order. The panel's title (an <h2> to <h6>, or the
<legend> of a <fieldset>) gets focus on every change, and the screen reader announces the new step.
<form method="post">
<div class="tuc-stepper" data-tuc-stepper>
<ol class="tuc-steps" aria-label="Sign-up steps">
<li class="tuc-steps__item" aria-current="step"><span class="tuc-steps__label">Details</span></li>
<li class="tuc-steps__item"><span class="tuc-steps__label">Address</span></li>
</ol>
<fieldset class="tuc-stepper__panel">
<legend>Your details</legend> …
</fieldset>
<fieldset class="tuc-stepper__panel" hidden>
<legend>Address</legend> …
</fieldset>
<div class="tuc-stepper__actions">
<button type="button" class="tuc-btn is-outline" data-step="prev" hidden>Back</button>
<button type="button" class="tuc-btn is-primary" data-step="next">Continue</button>
<button type="submit" class="tuc-btn is-primary" hidden>Finish</button>
</div>
</div>
</form>Continue checks the step's fields with the browser's own validation — required,
type="email", pattern, min — and doesn't move on if any fails: the field gets
aria-invalid="true" and the browser's message. Back never checks. On the first step Back goes away,
and on the last one Continue gives way to Finish. The hidden on those two in the template is what makes the bar
right before the script runs.
Why it's a single form
A hidden panel doesn't leave the DOM, so every name goes in the final POST, and the server receives exactly what it would from one long form. There's no JavaScript state to keep in sync, and server-side validation stays the same.
Enter in a text field, before the last step, is Continue. Without that it would submit the form, and the
browser would block the submission over a required field the person hasn't even seen yet, without saying which. A
reset on the form goes back to the first step.
With Django, when the server returns an error
A form that comes back from the POST with an error opens straight on the step of the first field with
aria-invalid="true" — which Django 5 writes on its own on every field that failed. Without that, the message
would be hidden two steps ahead.
<fieldset class="tuc-stepper__panel" hidden>
<legend>Address</legend>
{{ form.zip }} {# with an error, it comes with aria-invalid="true": the wizard opens here #}
{{ form.zip.errors }}
</fieldset>To open on a chosen step, use data-start="2" (counting from zero). Without it and without errors, the step marked
with aria-current="step" wins, or the first one. data-validate="false" lets the person move on without checking.
In JavaScript
const wizard = new Tucano.Stepper('#signup', {
start: 0, // initial step
validate: true, // Continue checks the step's fields
onChange: (index, { panel }) => console.log(index, panel),
});
wizard.next(); // checks and moves on
wizard.prev(); // goes back, without checking
wizard.go(2); // jumps straight there, without checking
wizard.go(0, { silent: true }); // without firing onChange
wizard.checkStep(); // true if the step's fields pass
wizard.index; // open stepEvery change fires tucano:change on the wizard element, and the event bubbles — it's the place to load the next
step through HTMX, if it depends on what was filled in before.
document.addEventListener('tucano:change', (e) => {
if (!e.target.matches('.tuc-stepper')) return;
e.detail.value; // step index
e.detail.step; // the indicator item
e.detail.panel; // the panel
e.detail.instance; // the Stepper
});Keyboard and accessibility
The indicator is an ordered list: the screen reader announces "item 2 of 3" without anyone writing ARIA, and
aria-current="step" says which one is current. On phones only the current step shows its name; the others'
names are still there for the screen reader.
| Key | Action |
|---|---|
Tab | The open step's fields and the buttons; hidden panels stay out of the way |
Enter | In a text field, before the last step: Continue. On the last one, submits the form |
Enter Space | On the buttons, the native click |
When the step changes, focus goes to the new panel's title, and the next Tab reaches the first field. The title
gets tabindex="-1" for that — focusable by the script, out of the Tab path.
API
Generated from the code on every build — if something is not here, it does not exist.
[data-tuc-stepper]new Tucano.Stepper(alvo, opcoes)data-start data-validatecheckStep next prev go destroytucano:changeOptions
The notes in this table come from comments in the source code, which are written in Portuguese.
| Option | Default | What for |
|---|---|---|
start | null | indice da etapa inicial; sem ele, a do primeiro campo com erro, a marcada com aria-current="step", ou a primeira |
validate | true | avancar confere os campos da etapa atual; voltar nunca confere |
onChange | null | (index, detail) a cada troca de etapa feita pela pessoa ou por go() |