HextaUI

Questionnaire: Auto-advance

With autoAdvance, picking a single answer moves on after a short pause, so you can answer with 1–5 alone. Changing an earlier answer never jumps ahead, and the last question never submits by itself.

"use client"

import {
  Questionnaire,
  QuestionnaireActions,
  QuestionnaireChoice,
  QuestionnaireChoices,
  QuestionnaireItem,
  QuestionnaireNext,
  QuestionnairePrevious,
  QuestionnaireProgress,
  QuestionnaireSubmit,
  QuestionnaireTitle,
} from "@/components/ui/questionnaire"

const scale = ["Not at all", "Slightly", "Moderately", "Very", "Extremely"]

const items = [
  { name: "useful", prompt: "How useful was today's session?" },
  { name: "pace", prompt: "How comfortable was the pace?" },
  { name: "recommend", prompt: "How likely are you to come back?" },
]

export function QuestionnaireAutoAdvance() {
  return (
    <div className="w-full max-w-md rounded-xl border p-5">
      <Questionnaire
        autoAdvance
        shortcuts="numbers"
        onSubmit={(event) => event.preventDefault()}
      >
        <QuestionnaireProgress />
        {items.map((item) => (
          <QuestionnaireItem key={item.name} name={item.name} required>
            <QuestionnaireTitle>{item.prompt}</QuestionnaireTitle>
            <QuestionnaireChoices>
              {scale.map((label) => (
                <QuestionnaireChoice key={label} value={label}>
                  {label}
                </QuestionnaireChoice>
              ))}
            </QuestionnaireChoices>
          </QuestionnaireItem>
        ))}
        <QuestionnaireActions>
          <QuestionnairePrevious />
          <QuestionnaireNext />
          <QuestionnaireSubmit />
        </QuestionnaireActions>
      </Questionnaire>
    </div>
  )
}

This adds the example as components/examples/questionnaire/auto-advance.tsx, together with the Questionnaire component and the HextaUI theme tokens it needs.

pnpm dlx shadcn@latest add https://hextaui.com/r/questionnaire-auto-advance.json

To add only the component, follow the Questionnaire installation.

Props in this example

The Questionnaire props this example sets, from the API reference.

PropTypeDefault
autoAdvanceMoves on 350ms after a single answer is picked for the first time.
booleanfalse
shortcutsAdds a key shortcut to every answer.
"letters" | "numbers"–
PropTypeDefault
nameThe form field name.
string–
required
booleanfalse
PropTypeDefault
value
string–

Every prop is in the Questionnaire API reference.

See them all, with keyboard support and accessibility notes, on the Questionnaire page.