Skip to content
GitHub11 stars

A multi-step questionnaire with single-choice, multiple-choice, freeform, and skippable questions.

Question 1 of 3
What should the agent build next?

Choose a direction or describe another task.

@inject ToastManager Toasts

<Questionnaire Class="mx-auto max-w-md" DefaultItem="direction" Items="@_items"

Installation

dnx Blazix.Cli add questionnaire

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
    └── QuestionnaireSubmit

Questionnaire 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.

What context should the agent inspect?

Select every source that may affect the implementation.

@inject ToastManager Toasts

<Questionnaire Class="mx-auto max-w-md" Items="@Items" Shortcuts="QuestionnaireShortcuts.Letters" OnSubmit="@HandleSubmit">

Freeform Answer

Compose QuestionnaireInput with fixed choices when the user can provide another answer.

How should the agent approach this refactor?

Choose a strategy or write a more specific instruction.

@inject ToastManager Toasts

<Questionnaire Class="mx-auto max-w-md" Items="@Items" Shortcuts="QuestionnaireShortcuts.Letters" OnSubmit="@HandleSubmit">

Explicit Skip

Add QuestionnaireSkip when an optional item may be intentionally left unanswered.

Question 1 of 3
What kind of change is this?

Choose the category that best describes the work.

@inject ToastManager Toasts

<Questionnaire Class="mx-auto max-w-md" DefaultItem="task" Items="@Items" OnSubmit="@HandleSubmit">

Shortcuts

Assign a letter or number key to each answer with Shortcuts.

What should the agent do next?

Use the displayed shortcut or navigate with the keyboard.

@inject ToastManager Toasts

<div class="mx-auto flex w-full max-w-md flex-col gap-6 self-stretch">

Custom Validation

Combine controlled navigation with your own validation to return to an invalid item and present its error.

How much detail should the answer include?

Choose the response depth.

1 / 2
@inject ToastManager Toasts

<Questionnaire Class="mx-auto max-w-md" @bind-Item="_item" Items="@Items" OnSubmit="@HandleSubmit">

Controlled

Control the active item from host state with @bind-Item, such as returning to an invalid step.

Current checkpoint: Change scope

Question 1 of 3
What may the agent change?

The host stores the active checkpoint while Questionnaire navigates.

@inject ToastManager Toasts

<div class="relative mx-auto flex h-full w-full max-w-md flex-col">

Resume

Restore a saved active item and default answers, then reset changes back to that saved state.

Question 2 of 3
How should the migration be verified?

These checks were selected during the previous session.

@inject ToastManager Toasts

<Questionnaire Class="mx-auto max-w-md" DefaultItem="verification" Items="@Items"

Conditional Items

Disable items that do not apply to the user's earlier answers.

Question 1 of 2
Where should the agent run?

Cloud runs add an environment question to this flow.

@inject ToastManager Toasts

<Questionnaire Class="mx-auto max-w-md" DefaultItem="runtime" Items="@_items" OnSubmit="@HandleSubmit">

Read item status to opt into disabled navigation and custom action styling.

Question 1 of 2
What may the agent modify?

Next is intentionally disabled until an answer is selected.

@inject ToastManager Toasts

<Questionnaire Class="mx-auto max-w-md" @bind-Item="_item" Items="@Items" OnSubmit="@HandleSubmit">

Custom Progress

Use the Render fragment of QuestionnaireProgress to build a custom progress indicator.

Checkpoint 1 of 4
How large is the change?
@inject ToastManager Toasts

<Questionnaire Class="mx-auto max-w-md" DefaultItem="scope" Items="@Items" OnSubmit="@HandleSubmit">

Animated Items

Animate the active item while keeping progress and navigation stationary.

Question 1 of 3
What should the agent do?

Choose the task for this run.

@inject ToastManager Toasts

<Questionnaire Class="mx-auto max-w-md" DefaultItem="task" Items="@Items" OnSubmit="@HandleSubmit">

Card

Compose Questionnaire with Card slots while keeping the question title and description semantic.

What should the agent work on?
Choose the task that should be handled next.
Question 1 of 2
@inject ToastManager Toasts

<Questionnaire Class="mx-auto max-w-md" DefaultItem="task" Items="@Items"

Dialog

Compose Questionnaire inside a Dialog while keeping cancellation and dismissal host-owned.

@inject ToastManager Toasts

<Dialog @bind-Open="_open">

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.

KeyBehavior
TabMoves focus between answer controls and visible actions.
ArrowUp / ArrowDownMoves to the previous or next answer from the item, a fixed answer, or an empty freeform input. Native radios also select it.
ArrowLeftMoves to the previous item when focus is outside a radio or text field.
ArrowRightMoves to the next item when the active item is answered or skipped and focus is outside a radio or text field.
SpaceSelects a radio, toggles a checkbox, or activates a focused action.
EnterContinues from a selected choice or a selected, filled input; activates a focused action.
Ctrl / Cmd + EnterValidates and continues from anywhere inside the questionnaire, or submits on the last item.

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.

السؤال ١ من ٣
ما الذي يجب أن يبنيه الوكيل بعد ذلك؟

اختر اتجاهًا.

@* Left and Right step through the questions as the reading direction runs: Right goes back in RTL. *@
<Questionnaire Class="mx-auto max-w-md" DefaultItem="direction" Items="@_items" Shortcuts="QuestionnaireShortcuts.Letters">
    <QuestionnaireProgress>

API Reference

Navigation components also take Button's Size and Variant, and QuestionnaireActions is a styled-only layout helper.

Questionnaire

ParameterTypeDefault
Render RenderFragment<QuestionnaireRenderProps>? -
Items IReadOnlyList<QuestionnaireItemDefinition>? -
DefaultItem string? -
Item string? -
ItemChanged EventCallback<string> -
Shortcuts QuestionnaireShortcuts? -
NoValidate bool true
OnSubmit EventCallback<QuestionnaireAnswers> -
OnReset EventCallback -
Class string? -
ChildContent RenderFragment? -

Other attributes are passed to the element it renders.

QuestionnaireActions

ParameterTypeDefault
Class string? -
ChildContent RenderFragment? -

Other attributes are passed to the element it renders.

QuestionnaireChoice

ParameterTypeDefault
Valuerequired string -
Checked bool? -
CheckedChanged EventCallback<bool> -
DefaultChecked bool false
Disabled bool false
Class string? -
ChildContent RenderFragment? -

Other attributes are passed to the element it renders.

QuestionnaireChoiceDescription

ParameterTypeDefault
Class string? -
ChildContent RenderFragment? -

Other attributes are passed to the element it renders.

QuestionnaireChoices

ParameterTypeDefault
Render RenderFragment<QuestionnaireChoicesRenderProps>? -
Class string? -
ChildContent RenderFragment? -

Other attributes are passed to the element it renders.

QuestionnaireDescription

ParameterTypeDefault
Render RenderFragment<PartRenderProps>? -
Class string? -
ChildContent RenderFragment? -

Other attributes are passed to the element it renders.

QuestionnaireError

ParameterTypeDefault
Render RenderFragment<QuestionnaireErrorRenderProps>? -
Class string? -
ChildContent RenderFragment? -

Other attributes are passed to the element it renders.

QuestionnaireInput

ParameterTypeDefault
Value string? -
ValueChanged EventCallback<string?> -
DefaultValue string? -
Disabled bool false
Type string "text"
Class string? -

Other attributes are passed to the element it renders.

QuestionnaireItem

ParameterTypeDefault
Render RenderFragment<QuestionnaireItemRenderProps>? -
Namerequired string -
Required bool false
Multiple bool false
Disabled bool false
Invalid bool false
OnStatusChange EventCallback<QuestionnaireItemStatus> -
Class string? -
ChildContent RenderFragment? -

Other attributes are passed to the element it renders.

QuestionnaireNext

ParameterTypeDefault
Render RenderFragment<QuestionnaireNavigationRenderProps>? -
Variant ButtonVariant ButtonVariant.Default
Size ButtonSize ButtonSize.Default
Disabled bool false
Class string? -
ChildContent RenderFragment? -

Other attributes are passed to the element it renders.

QuestionnairePrevious

ParameterTypeDefault
Render RenderFragment<QuestionnaireNavigationRenderProps>? -
Variant ButtonVariant ButtonVariant.Outline
Size ButtonSize ButtonSize.Default
Disabled bool false
Class string? -
ChildContent RenderFragment? -

Other attributes are passed to the element it renders.

QuestionnaireProgress

ParameterTypeDefault
Render RenderFragment<QuestionnaireRenderProps>? -
Class string? -
ChildContent RenderFragment? -

Other attributes are passed to the element it renders.

QuestionnaireSkip

ParameterTypeDefault
Render RenderFragment<QuestionnaireNavigationRenderProps>? -
Variant ButtonVariant ButtonVariant.Outline
Size ButtonSize ButtonSize.Default
Disabled bool false
Class string? -
ChildContent RenderFragment? -

Other attributes are passed to the element it renders.

QuestionnaireSubmit

ParameterTypeDefault
Render RenderFragment<QuestionnaireNavigationRenderProps>? -
Variant ButtonVariant ButtonVariant.Default
Size ButtonSize ButtonSize.Default
Disabled bool false
Class string? -
ChildContent RenderFragment? -

Other attributes are passed to the element it renders.

QuestionnaireTitle

ParameterTypeDefault
Render RenderFragment<PartRenderProps>? -
Class string? -
ChildContent RenderFragment? -

Other attributes are passed to the element it renders.