Questionnaire
Multi-step questionnaire flow built on the shadcn Questionnaire primitive.
Installation
Bash
Depends on the @shadcn/react package, installed automatically.
Usage
The root renders a real <form>: each QuestionnaireItem is a
fieldset named question, progression and validation are managed
internally, and answers arrive as FormData in onSubmit (use
getAll for multiple items). Navigation buttons show and hide
themselves — Next hides on the last step, Submit appears there, Skip
only renders on non-required items.
API reference
Questionnaire
Extends form.
| Prop | Type | Default |
|---|---|---|
defaultItem | string | — |
item | string | — |
onItemChange | (item: string) => void | — |
items | readonly QuestionnaireItemDefinition[] | — |
shortcuts | "letters" | "numbers" | — |
onSubmit | React.FormEventHandler<HTMLFormElement> | — |
item/onItemChange control the active step externally (by item
name); shortcuts enables keyboard selection and shows the shortcut
chips on choices.
QuestionnaireItem
Extends fieldset. One question per item; only the active one is
shown.
| Prop | Type | Default |
|---|---|---|
name | string (required) | — |
multiple | boolean — checkbox behavior instead of radio | false |
required | boolean | false |
invalid | boolean — force invalid styling (external validation) | — |
onStatusChange | (status: "unanswered" | "answered" | "skipped") => void | — |
QuestionnaireChoice
Extends label; the hidden input, indicator (radio dot / check), label,
and shortcut chip are built in.
| Prop | Type | Default |
|---|---|---|
value | string (required) | — |
checked / defaultChecked | boolean | — |
disabled | boolean | false |
onChange | React.ChangeEventHandler<HTMLInputElement> | — |
QuestionnaireInput
Freeform answer field for the active item.
| Prop | Type | Default |
|---|---|---|
type | "text" | "email" | "number" | "date" | "tel" | … | "text" |
QuestionnairePrevious, QuestionnaireSkip, QuestionnaireNext, QuestionnaireSubmit
Navigation buttons styled through
Button’s variants (variant and size
props apply; Previous/Skip default to outline). They disable and hide
themselves based on position and item state. Default labels can be
replaced via children.
QuestionnaireProgress, QuestionnaireTitle, QuestionnaireDescription, QuestionnaireChoiceDescription, QuestionnaireError, QuestionnaireActions
Presentation parts: progress (“x of y”, with { current, total, first, last } available via the render prop), the question heading
(legend) and description, per-choice helper text, the validation
message slot, and the action-row grid.