Skip to content
GitHub11 stars

A multi-step form that asks one question at a time, with single-choice, multiple-choice, freeform and skippable questions.

Question 1 of 2
Which theme do you prefer?

You can change it later in settings.

@if (_submitted)
{
    <div class="questionnaire-done">

These are the headless parts of Questionnaire, which the styled Questionnaire is built on. Only the active item is shown. Previous, Skip, Next and Submit move through the items, validating the active one first.

Anatomy

Import the primitives and assemble the parts:

@using Blazix.Primitives

<QuestionnaireRoot>
    <QuestionnaireProgress />
    <QuestionnaireItem>
        <QuestionnaireTitle />
        <QuestionnaireDescription />
        <QuestionnaireChoices>
            <QuestionnaireChoice>
                <QuestionnaireChoiceInput />
                <QuestionnaireChoiceLabel />
                <QuestionnaireChoiceShortcut />
            </QuestionnaireChoice>
            <QuestionnaireInput />
        </QuestionnaireChoices>
        <QuestionnaireError />
    </QuestionnaireItem>
    <QuestionnairePrevious />
    <QuestionnaireSkip />
    <QuestionnaireNext />
    <QuestionnaireSubmit />
</QuestionnaireRoot>

Keyboard

  • Ctrl+Enter (Cmd+Enter on macOS) confirms the active item.
  • ↑ and ↓ move between the item's answers, and ← and → between items.
  • Enter on a filled answer confirms it.
  • With Shortcuts set, letters (A–Z) or numbers (1–9) select answers.

API Reference

QuestionnaireRoot

Renders a <form> element.

ParameterTypeDefault
Items IReadOnlyList<QuestionnaireItemDefinition>? -
DefaultItem string? -
Item string? -
ItemChanged

Called with the new value when Item changes, for @bind-Item.

EventCallback<string> -
Shortcuts QuestionnaireShortcuts? -
NoValidate bool true
OnSubmit EventCallback<QuestionnaireAnswers> -
OnReset EventCallback -
Render RenderFragment<QuestionnaireRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

AttributeType
data-current

The number of the active item, counting from 1.

number
data-total

How many items there are.

number
data-first

Present when the first item is active.

-
data-last

Present when the last item is active.

-
data-shortcuts

Which keys select answers, when shortcuts are on.

'letters' | 'numbers'

QuestionnaireProgress

Renders a <div> element.

ParameterTypeDefault
Render RenderFragment<QuestionnaireRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

AttributeType
data-current

The number of the active item, counting from 1.

number
data-total

How many items there are.

number
data-first

Present when the first item is active.

-
data-last

Present when the last item is active.

-

QuestionnaireItem

Renders a <fieldset> element.

ParameterTypeDefault
Namerequired string -
Required

Whether the user must enter a value before submitting a form.

bool false
Multiple bool false
Disabled

Whether the component should ignore user interaction.

bool false
Invalid bool false
OnStatusChange EventCallback<QuestionnaireItemStatus> -
Render RenderFragment<QuestionnaireItemRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

AttributeType
data-active

Present while the item is the one shown.

-
data-status

Whether the item has been answered or skipped.

'unanswered' | 'answered' | 'skipped'
data-multiple

Present when the item takes several answers.

-
data-required

Present when the item must be answered.

-
data-invalid

Present when the item failed validation.

-
data-disabled

Present when the item is disabled.

-

QuestionnaireTitle

Renders a <legend> element.

ParameterTypeDefault
Render RenderFragment<PartRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

QuestionnaireDescription

Renders a <p> element.

ParameterTypeDefault
Render RenderFragment<PartRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

QuestionnaireChoices

Renders a <div> element.

ParameterTypeDefault
Render RenderFragment<QuestionnaireChoicesRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

AttributeType
data-shortcuts

Which keys select answers, when shortcuts are on.

'letters' | 'numbers'

QuestionnaireChoice

Renders a <label> element.

ParameterTypeDefault
Valuerequired string -
Checked bool? -
CheckedChanged

Called with the new value when Checked changes, for @bind-Checked.

EventCallback<bool> -
DefaultChecked bool false
Disabled

Whether the component should ignore user interaction.

bool false
Render RenderFragment<QuestionnaireChoiceRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

AttributeType
data-checked

Present when the choice is selected.

-
data-unchecked

Present when the choice isn't selected.

-
data-type

Whether the item takes one answer or several.

'radio' | 'checkbox'
data-shortcut

The choice's shortcut key, when shortcuts are on.

string
data-invalid

Present when the item failed validation.

-
data-disabled

Present when the choice is disabled.

-

QuestionnaireChoiceInput

Renders a <input> element.

ParameterTypeDefault
Render RenderFragment<QuestionnaireChoiceRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

QuestionnaireChoiceLabel

Renders a <span> element.

ParameterTypeDefault
Render RenderFragment<PartRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

QuestionnaireChoiceShortcut

Renders a <span> element.

ParameterTypeDefault
Render RenderFragment<QuestionnaireChoiceShortcutRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

AttributeType
data-shortcut

The shortcut key.

string

QuestionnaireInput

Renders a <input> element.

ParameterTypeDefault
Value string? -
ValueChanged

Called with the new value when Value changes, for @bind-Value.

EventCallback<string?> -
DefaultValue string? -
Disabled

Whether the component should ignore user interaction.

bool false
Type string "text"
Render RenderFragment<QuestionnaireInputRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

AttributeType
data-filled

Present when the input holds more than whitespace.

-
data-empty

Present when the input is empty.

-
data-invalid

Present when the item failed validation.

-
data-disabled

Present when the input is disabled.

-

QuestionnaireError

Renders a <p> element.

ParameterTypeDefault
Render RenderFragment<QuestionnaireErrorRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

AttributeType
data-invalid

Present while the item is invalid and the error shows.

-

QuestionnairePrevious

Renders a <button> element.

ParameterTypeDefault
Disabled

Whether the component should ignore user interaction.

bool false
Render RenderFragment<QuestionnaireNavigationRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

AttributeType
data-visible

Present when the button applies to the active item.

-
data-hidden

Present when it doesn't, e.g. Previous on the first item.

-
data-status

The active item's status.

'unanswered' | 'answered' | 'skipped'
data-disabled

Present when the button is disabled.

-

QuestionnaireSkip

Renders a <button> element.

ParameterTypeDefault
Disabled

Whether the component should ignore user interaction.

bool false
Render RenderFragment<QuestionnaireNavigationRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

QuestionnaireNext

Renders a <button> element.

ParameterTypeDefault
Disabled

Whether the component should ignore user interaction.

bool false
Render RenderFragment<QuestionnaireNavigationRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

QuestionnaireSubmit

Renders a <button> element.

Skip, Next and Submit render the same data attributes as Previous.

ParameterTypeDefault
Disabled

Whether the component should ignore user interaction.

bool false
Render RenderFragment<QuestionnaireNavigationRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.