Questionnaire
A multi-step questionnaire with single-choice, multiple-choice, freeform, and skippable questions.
Installation
Usage
@code {
private sealed record Choice(string Value, string Label, string? Description = null);
private sealed record FreeformInput(string Label, string Placeholder);
private sealed record Question(string Name, bool Required, string Prompt, string Description,
Choice[] Choices, FreeformInput? Input = null);
private static readonly Question[] Questions =
[
new("direction", true, "What should we prototype next?", "Choose a direction or write your own.",
[
new("delegation", "Delegation", "Show how work moves to a specialist."),
new("questions", "Question prompts", "Show choices while the interface waits."),
new("both", "Both together"),
],
new("Another answer", "Type another answer…")),
new("detail", false, "How much detail should it include?", "Skip this if you are not sure yet.",
[new("focused", "Focused"), new("complete", "Complete flow")]),
];
private static readonly Blazix.Primitives.QuestionnaireItemDefinition[] Definitions =
Questions.Select(q => new Blazix.Primitives.QuestionnaireItemDefinition(q.Name, q.Required)).ToArray();
private void HandleSubmit(Blazix.Primitives.QuestionnaireAnswers answers)
{
var direction = answers.Get("direction");
}
}Define the collection once: pass it to Items on Questionnaire so progress, actions, and shortcuts are right on the first render, then map it into the parts. OnSubmit receives the answers: Get returns an item's answer, and GetAll every answer of an item that takes several.
<Questionnaire Items="@Definitions" OnSubmit="@HandleSubmit">
<QuestionnaireProgress />
@foreach (var question in Questions)
{
<QuestionnaireItem @key="question.Name" Name="@question.Name" Required="@question.Required">
<QuestionnaireTitle>@question.Prompt</QuestionnaireTitle>
<QuestionnaireDescription>@question.Description</QuestionnaireDescription>
<QuestionnaireChoices>
@foreach (var choice in question.Choices)
{
<QuestionnaireChoice @key="choice.Value" Value="@choice.Value">
<span class="font-medium">@choice.Label</span>
@if (choice.Description is not null)
{
<span class="text-muted-foreground">@choice.Description</span>
}
</QuestionnaireChoice>
}
@if (question.Input is { } input)
{
<QuestionnaireInput aria-label="@input.Label" placeholder="@input.Placeholder" />
}
</QuestionnaireChoices>
<QuestionnaireError />
</QuestionnaireItem>
}
<QuestionnaireActions>
<QuestionnairePrevious />
<QuestionnaireSkip />
<QuestionnaireNext />
<QuestionnaireSubmit />
</QuestionnaireActions>
</Questionnaire>Composition
Questionnaire
├── QuestionnaireProgress
├── QuestionnaireItem
│ ├── QuestionnaireTitle
│ ├── QuestionnaireDescription
│ ├── QuestionnaireChoices
│ │ ├── QuestionnaireChoice
│ │ └── QuestionnaireInput
│ └── QuestionnaireError
└── QuestionnaireActions
├── QuestionnairePrevious
├── QuestionnaireSkip
├── QuestionnaireNext
└── QuestionnaireSubmitQuestionnaire owns the ordered items, active item, answer state, validation, progress, and navigation. The containing page, card, dialog, or drawer owns close and cancellation behavior, persistence, transport, and branching.
Server Rendering
Pass Items to render the active item, progress, actions, and answer shortcuts before the items register, including during prerendering.
Multiple Selection
Use Multiple for an item that accepts more than one fixed answer.
Freeform Answer
Compose QuestionnaireInput with fixed choices when the user can provide another answer.
Explicit Skip
Add QuestionnaireSkip when an optional item may be intentionally left unanswered.
Shortcuts
Assign a letter or number key to each answer with Shortcuts.
Custom Validation
Combine controlled navigation with your own validation to return to an invalid item and present its error.
Controlled
Control the active item from host state with @bind-Item, such as returning to an invalid step.
Current checkpoint: Change scope
Resume
Restore a saved active item and default answers, then reset changes back to that saved state.
Conditional Items
Disable items that do not apply to the user's earlier answers.
Navigation State
Read item status to opt into disabled navigation and custom action styling.
Custom Progress
Use the Render fragment of QuestionnaireProgress to build a custom progress indicator.
Animated Items
Animate the active item while keeping progress and navigation stationary.
Card
Compose Questionnaire with Card slots while keeping the question title and description semantic.
Dialog
Compose Questionnaire inside a Dialog while keeping cancellation and dismissal host-owned.
Accessibility
QuestionnaireItem renders a fieldset, and QuestionnaireTitle renders its legend. Descriptions and active errors are associated with the current item, and invalid items and answer controls expose aria-invalid. If the title renders something else through Render, give it an id and point the item's aria-labelledby at it, as the Card example does.
Fixed choices preserve native radio and checkbox behavior. Progress is exposed as a named progressbar, navigation uses real buttons, and inactive items and actions are hidden and inert. Successful navigation focuses the newly active item; failed validation focuses an available answer control.
Always give QuestionnaireInput an accessible name with a visible label, aria-label, or aria-labelledby. A placeholder is not a label.
Shortcuts and arrow navigation pause while you type in a text field.
Unstyled
The behavior comes from the Questionnaire parts in Blazix.Primitives (QuestionnaireRoot, QuestionnaireItem, QuestionnaireChoice, QuestionnaireChoiceInput, and the rest). Use them directly with your own markup and styles.
RTL
To enable RTL support in Blazix, see the RTL configuration guide.
Translated with AI for the demo, so it may have mistakes.
API Reference
Navigation components also take Button's Size and Variant, and QuestionnaireActions is a styled-only layout helper.
Questionnaire
Other attributes are passed to the element it renders.
QuestionnaireActions
Other attributes are passed to the element it renders.
QuestionnaireChoice
Other attributes are passed to the element it renders.
QuestionnaireChoiceDescription
Other attributes are passed to the element it renders.
QuestionnaireChoices
Other attributes are passed to the element it renders.
QuestionnaireDescription
Other attributes are passed to the element it renders.
QuestionnaireError
Other attributes are passed to the element it renders.
QuestionnaireInput
Other attributes are passed to the element it renders.
QuestionnaireItem
Other attributes are passed to the element it renders.
QuestionnaireNext
Other attributes are passed to the element it renders.
QuestionnairePrevious
Other attributes are passed to the element it renders.
QuestionnaireProgress
Other attributes are passed to the element it renders.
QuestionnaireSkip
Other attributes are passed to the element it renders.
QuestionnaireSubmit
Other attributes are passed to the element it renders.
QuestionnaireTitle
Other attributes are passed to the element it renders.