Questionnaire
One question at a time, with forward and back — for asking a reader more than a single screen should ask at once.
Questionnaire
One question at a time, forward and back, with the step counter reading off how many there are. No question carries an index: the items register themselves as they mount, so DOM order is step order and inserting a question renumbers nothing. Answers come back as arrays whatever the question took.
Usage
import {
Questionnaire,
QuestionnaireActions,
QuestionnaireChoice,
QuestionnaireChoiceDescription,
QuestionnaireChoices,
QuestionnaireDescription,
QuestionnaireError,
QuestionnaireItem,
QuestionnaireNext,
QuestionnairePrevious,
QuestionnaireProgress,
QuestionnaireSkip,
QuestionnaireSubmit,
QuestionnaireTitle,
useQuestionnaire,
} from '@oceanic-hub/brand-system'<Questionnaire>
<QuestionnaireProgress>…</QuestionnaireProgress>
<QuestionnaireItem name="…">
<QuestionnaireTitle>…</QuestionnaireTitle>
<QuestionnaireDescription>…</QuestionnaireDescription>
<QuestionnaireChoices>
<QuestionnaireChoice value="…">
<QuestionnaireChoiceDescription>…</QuestionnaireChoiceDescription>
</QuestionnaireChoice>
</QuestionnaireChoices>
</QuestionnaireItem>
<QuestionnaireActions>
<QuestionnairePrevious>…</QuestionnairePrevious>
<QuestionnaireNext>…</QuestionnaireNext>
<QuestionnaireSubmit>…</QuestionnaireSubmit>
</QuestionnaireActions>
</Questionnaire>Composition
Use the following composition to build a Questionnaire:
Questionnaire
├── QuestionnaireProgress
├── QuestionnaireItem ×3
│ ├── QuestionnaireTitle
│ ├── QuestionnaireDescription
│ ├── QuestionnaireChoices
│ │ └── QuestionnaireChoice ×3
│ │ └── QuestionnaireChoiceDescription
│ └── QuestionnaireError
└── QuestionnaireActions
├── QuestionnairePrevious
├── QuestionnaireNext
├── QuestionnaireSubmit
└── QuestionnaireSkip
QuestionnaireNext
QuestionnaireItem
├── QuestionnaireTitle
├── QuestionnaireDescription
└── QuestionnaireChoices
└── QuestionnaireChoice ×2Reach for it when the answers are independent and the reader benefits from seeing one
thing: onboarding, a qualification flow, a survey. Do not reach for it when the answers
inform each other — if someone has to look back at question two to answer question five, a
questionnaire has hidden the context they need and Form is the component that shows it. The
same goes for anything a reader will want to review before submitting: this shows one item and
its own error, never the whole sheet.
The sequence comes from the markup, and that has one consequence worth reading twice. Items
register themselves as they mount, in DOM order, so nothing carries an index and nobody has to
renumber questions when one is inserted. The price is that mount order is the only order a
registry can see: an item rendered conditionally appears late and registers at the end,
however early it sits. So a question that only sometimes applies is disabled, not unmounted —
it leaves the steps and the count, keeps its place, and comes back where the markup puts it
(@OCE-1869). Removing one is no longer silently broken either, since an unmounting item now
unregisters, but it still cannot come back in order. Branch on whether an item is disabled,
never on whether it exists.
Answers are always arrays, single choice included, so a submit handler never branches on whether
a question took one answer or many. onComplete fires on a real form submit and hands back the
answers — it is not onSubmit and it does not fire on each Next. It is not gated to the
last step: QuestionnaireSubmit only renders there, but any submit reaches the handler, so
guard on isLast yourself.
required is enforced, and anything past it is yours. Next refuses while a required
question is empty and sets that item's error; answering clears it; Finish refuses the same way, so
the last question cannot be submitted blank (@OCE-1869). Only the VISIBLE question is checked —
raising an error on one a reader cannot see is a button that appears to do nothing — and
QuestionnaireSkip bypasses the check deliberately, which makes a Skip beside a required
question a contradiction worth not writing. For a rule required cannot express — "at least
two", a format, an answer that depends on an earlier one — the parts are there: useQuestionnaire
hands you the answers and a way to set an error, and the navigation buttons spread their props
last, so an onClick you pass replaces the built-in advance rather than running beside it.
Check, set the error, and call next yourself when it passes. The error renders as a mark and a
sentence, never as a question turned red.
Where this differs from shadcn's page, and why. Every part is prefixed —
QuestionnaireItem, not Item — because upstream's dot notation flattens onto three names
this package already owns. There is no freeform input part: a text answer is Input or
Textarea composed inside the question, both of which already exist here, and a third text
control that happens to live in a questionnaire is the duplication the layer rules exist to
prevent. There is no per-question status part either; a screen showing every question's state at
once is the opposite of a stepped questionnaire, and would be a different component.
Four upstream examples have no answer here and are refused rather than approximated: keyboard
shortcuts on choices, a controlled active step owned by the host, resuming to a saved
step (seeded answers work, the step does not), and animated transitions between questions —
the swap is a visibility toggle with no state attribute to key motion on, and motion that
carried the change alone would vanish under reduced motion anyway. Wrapping the whole thing in a
Card or a Dialog needs nothing special: it is an ordinary child.
One caveat about this component's standing. Its surface is not parity-verified and cannot be
— questionnaire is listed in shadcn's registry but its source 404s at every style path, so
there is no upstream file to diff. The names follow the documented anatomy; everything else is
ours. It also entered the package on an explicit waiver rather than by clearing the promotion
bar, and no Oceanic surface runs a stepped questionnaire yet.
Multiple selection
multiple on a question lets a reader pick several, and the marker changes shape to say so before they try — square for many, round for one, the same distinction a checkbox and a radio already make. Reach for it when the answers are additive; if picking one has to unpick another, that is a single-choice question wearing the wrong marker.
A freeform answer
There is no text-input part here, on purpose — a written answer is Input or Textarea, both of which the package already ships, composed inside the question. useQuestionnaire gives the control the same place to write as a choice has, so a freeform answer lands in the same values map, under the same name, as an array like every other answer.
Skippable questions
QuestionnaireSkip advances without answering and, being a real button, says so out loud — which is the point. Reach for it on a question you would rather ask than force: a reader who has no answer will otherwise invent one, and an invented answer is worse than a gap. Leave it off the questions the flow genuinely cannot continue without.
Required answers
required on an item is enforced: Next refuses while the question is empty and sets the error the QuestionnaireError in that item renders, and answering clears it. Finish is refused the same way, so the last question cannot be submitted blank either.
Custom validation
For a rule required cannot express — "at least two", a format, an answer that depends on an earlier one. The navigation buttons spread their props last, so an onClick you pass REPLACES the built-in advance instead of racing it: check, setError, and call next yourself when it passes. Reach for a blocked button with a reason over a disabled one, which tells a reader they are stuck without telling them why.
Conditional questions
Branch by DISABLING an item, never by unmounting it. A disabled question leaves the steps and the count, keeps its place in the order, and comes back exactly where the markup puts it — whereas one that mounts late registers at the end however early it sits.
A progress bar instead
The built-in read-out is a count — "2 of 5" — because at this scale a number is more useful than a proportion: a reader wants to know how many are left, not what fraction is done. When the set is long enough that the number stops meaning anything, read the same step and count off useQuestionnaire and hand them to Progress. Show one or the other, never both.
In a card
The root is an ordinary child, so a Card can carry the title, the boundary and the footer while the questionnaire carries only the question. Reach for this when the flow sits on a page beside other things and needs an edge of its own; a Dialog composes exactly the same way, with the host keeping ownership of dismissal.
Set up your workspace
Three questions, then we will finish the rest for you.
API Reference
See the Questionnaire API page for every prop of every part, with types, defaults and the contract that pins them. It also documents useQuestionnaire — exported alongside the parts, and signatures rather than props.