Skip to content
RunsQuestionnaireMenu

Questionnaire

Clarifying questions from the agent, one at a time: single choice, multiple choice with Other, and free text, with Skip, a stepper and a summary before sending.

Single choice, multiple choice with Other, and free text, then a summary before sending.

Installation

$ pnpm dlx shadcn@latest add https://chatcn.dev/r/questionnaire.json

Usage

tsx
import { Questionnaire } from "@/components/ui/chatcn/questionnaire"

<Questionnaire
  title="A few questions before I add CSV export"
  questions={[
    { id: "scope", type: "single", title: "Which runs?", options: [...] },
    { id: "columns", type: "multi", title: "Which columns?", options: [...], allowOther: true },
    { id: "notes", type: "text", title: "Anything else?" },
  ]}
  onSubmit={(answers) => sendToAgent(answers)}
/>

Use describeAnswer(question, answer) to turn an answer into one readable line for the model. Set submitted after sending to collapse the card into a read-only summary.

Examples

Answered

The compact read-only state after the answers are sent.

Props

PropTypeNotes
questionsQuestionnaireQuestion[]{ id, type, title, description?, options?, allowOther?, placeholder?, required? }
value, defaultValue, onValueChangeQuestionnaireAnswersControlled or uncontrolled
onSubmit(answers) => voidFrom the summary step
onDismiss() => voidShows Skip all
submittedbooleanCompact read-only state
title, submitLabelHeader text and final button label

Keyboard

KeyAction
ArrowUp, ArrowDownMove between choices
1 to 9Pick a choice
EnterPick the focused choice, or go on once answered
Shift+Enter in textNew line. Enter never fires during IME composition

Accessibility

  • Single choice is a radiogroup of radio buttons with a roving tab stop; multiple choice is a group of checkbox buttons.
  • The 1 of 3 counter is a polite live region. Stepper segments are buttons named Question 2, answered.
  • The card never steals focus on mount. Focus follows the step only when it was already inside.

Motion

  • Steps changed with the pointer slide 8 px in their direction with a 180 ms fade. Steps changed with the keyboard swap instantly.
  • Choice indicators fill over 150 ms. Under reduced motion only the fade remains.