Sub topic 3
Showing Progress When the Path Varies
Assume you know basic TypeScript, forms, and application state. This chapter covers progress, review, drafts, accessibility, and testing for a branched screen flow.
Showing progress when the path varies
A fixed label such as “Step 2 of 4” becomes misleading when an earlier answer adds or removes steps. Prefer a stable label based on completed history, or show named stages.
type FlowState = {
current: string;
history: string[];
};
function progressLabel(state: FlowState): string {
return `Step ${state.history.length + 1}`;
}
const state: FlowState = {
current: "company",
history: ["account"],
};
console.log(progressLabel(state)); // Step 2A progress bar can show completion relative to known milestones, but do not imply a precise total if the path can change.
Reviewing and submitting
A review step should display the collected values and provide an edit action for each section. Reuse the same validation rules during final submission. The server must validate again because client state can be stale or modified.
Saving drafts and resuming later
Persist partial data after meaningful changes, not only when the user clicks Next. Store the current step with the data and a version number.
type Draft = {
version: number;
current: string;
data: Record<string, string>;
};
function saveDraft(state: Draft): void {
localStorage.setItem("signup-draft", JSON.stringify(state));
}
function loadDraft(): Draft | null {
const raw = localStorage.getItem("signup-draft");
return raw ? JSON.parse(raw) as Draft : null;
}Avoid storing sensitive information in browser storage unless the risk is acceptable. Expire drafts and handle schema changes.
Making step changes accessible
Move focus to the new step heading after navigation. Associate each error with its field, summarize errors near the heading, and announce changes with an appropriate live region. Preserve entered values when returning with Back.
Testing the paths through a flow
Test each branch, invalid input, Back navigation, draft restoration, and duplicate submission. Assert user-visible outcomes rather than internal calls.
Exercise
Why should a branched flow avoid promising a fixed total step count?
Show answer
The user's answers can add or remove steps, so a fixed total can become inaccurate.