Make your AI a shadcn expert

Shadcn Questionnaire

React questionnaire for onboarding, intake, and research flows. Built with TypeScript and Tailwind CSS for Next.js using Base UI — choices, freeform, skip, and progress.

A questionnaire is a multi-step form with one question on screen. Use it for onboarding, intake, or a research flow. Single choice, multiple, or a text field — then Next, Skip, or Submit.

Scroll to load preview...

Usage

import {
  Questionnaire,
  QuestionnaireActions,
  QuestionnaireChoice,
  QuestionnaireChoices,
  QuestionnaireItem,
  QuestionnaireNext,
  QuestionnaireProgress,
  QuestionnaireSubmit,
  QuestionnaireTitle,
} from "@/components/ui/questionnaire"
<Questionnaire items={items} onSubmit={handleSubmit}>
  <QuestionnaireProgress />
  {items.map(item => (
    <QuestionnaireItem key={item.name} name={item.name} required={item.required}>
      <QuestionnaireTitle>{item.title}</QuestionnaireTitle>
      <QuestionnaireChoices>
        {item.choices.map(choice => (
          <QuestionnaireChoice key={choice.value} value={choice.value}>
            {choice.label}
          </QuestionnaireChoice>
        ))}
      </QuestionnaireChoices>
    </QuestionnaireItem>
  ))}
  <QuestionnaireActions>
    <QuestionnaireNext />
    <QuestionnaireSubmit />
  </QuestionnaireActions>
</Questionnaire>

Pass the same items array to the root so progress, shortcuts, and skip know the list. onSubmit gets a form event — read FormData.

Composition

QuestionnaireProgress
QuestionnaireTitle
QuestionnaireDescription
QuestionnaireChoice
QuestionnaireInput
QuestionnaireError

Multiple Selection

multiple on the item. FormData.getAll(name) returns every checked value.

Scroll to load preview...

Freeform Answer

QuestionnaireInput next to the choices. They type when none of the chips fit.

Scroll to load preview...

Explicit Skip

QuestionnaireSkip on an optional item. Required items hide Skip.

Scroll to load preview...

Shortcuts

shortcuts="letters" — A, B, C pick a choice. Arrow keys still move.

Scroll to load preview...

Custom Validation

QuestionnaireError under the choices. Block Next until the item is valid.

Scroll to load preview...

Controlled

Hold the current item id in state. Resume, deep-link, or drive it from a stepper.

Scroll to load preview...

Resume

Seed defaultItem from storage. They land on the last unanswered question.

Scroll to load preview...

Conditional Items

Drop or add items from the list based on a previous answer. The root re-reads items.

Scroll to load preview...

Disable Previous on the first item. Swap Next for Submit on the last.

Scroll to load preview...

Custom Progress

QuestionnaireProgress can render a fraction, a bar, or both.

Scroll to load preview...

Animated Items

Animate the incoming question. Keep the chrome still.

Scroll to load preview...

Card

Wrap the questionnaire in a Card when it is a section, not the page.

Scroll to load preview...

Dialog

Same flow inside a Dialog. Good for a mid-task prompt.

Scroll to load preview...

API

Prop

Type

QuestionnaireItem

Prop

Type

Keyboard

KeyAction
TabMove between choices and actions
Space / EnterSelect the focused choice
AZPick a choice when shortcuts="letters"
Arrow keysMove through choices

Notes

One items array

Pass the same list to Questionnaire and to the map that renders items. Two copies drift — progress counts one list, the screen shows the other.

Read answers from FormData. Don't keep a parallel state object unless you are controlling the current item.

With other components

Questions

Was this page helpful?

Sign in to leave feedback.