Skip to content
All components
Conversation

Questionnaire

Ask a short structured question inside a conversation and offer a few answers that are quicker to tap than to type.

A structured question with answers that are quicker to tap than to type.

Installation

tdpxl is not an npm dependency of your app. The @tdpxl/cli command (not published to npm yet) copies the source into your project, with the registry items and npm packages it imports.

npx @tdpxl/cli add questionnaire

Then import it from @/components/ui/questionnaire. New project? Start with the installation guide.

Examples

Each example is one branch of the official demo, rendered in its own frame. The code is that branch as you would write it, with imports pointing at the default install paths.

Multiple answers

Let people choose several answers before sending. Each option is a pressed button; the group is named by the question and the send action stays disabled until something is chosen. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import * as React from "react"

import { Button } from "@/components/ui/button"
import {
  Questionnaire,
  QuestionnaireDescription,
  QuestionnaireFooter,
  QuestionnaireOption,
  QuestionnaireOptions,
  QuestionnaireTitle,
} from "@/components/ui/questionnaire"

const topics = ["Billing", "Account access", "Data export", "Integrations", "Something else"]

function MultipleAnswers() {
  const [selected, setSelected] = React.useState<string[]>([])

  function toggle(topic: string) {
    setSelected((current) =>
      current.includes(topic) ? current.filter((item) => item !== topic) : [...current, topic]
    )
  }

  return (
    <Questionnaire>
      <QuestionnaireTitle id="questionnaire-topics">What do you need help with?</QuestionnaireTitle>
      <QuestionnaireDescription id="questionnaire-topics-hint">
        Choose all that apply.
      </QuestionnaireDescription>
      <QuestionnaireOptions
        aria-labelledby="questionnaire-topics"
        aria-describedby="questionnaire-topics-hint"
      >
        {topics.map((topic) => (
          <QuestionnaireOption
            key={topic}
            selected={selected.includes(topic)}
            onClick={() => toggle(topic)}
          >
            {topic}
          </QuestionnaireOption>
        ))}
      </QuestionnaireOptions>
      <QuestionnaireFooter>
        <p className="me-auto text-paragraph-sm text-sub-600">{selected.length} selected</p>
        <Button type="button" size="xs" disabled={selected.length === 0}>
          Send answers
        </Button>
      </QuestionnaireFooter>
    </Questionnaire>
  )
}

export function QuestionnaireMultipleAnswers() {
  return (
    <div className="flex w-full max-w-md flex-col gap-8">
      <MultipleAnswers />
    </div>
  )
}

Answer sent

Show an answered question as read-only. Options are disabled, the chosen one stays marked and a sentence confirms what was sent. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import {
  Questionnaire,
  QuestionnaireDescription,
  QuestionnaireOption,
  QuestionnaireOptions,
  QuestionnaireTitle,
} from "@/components/ui/questionnaire"

export function QuestionnaireAnswerSent() {
  return (
    <div className="flex w-full max-w-md flex-col gap-8">
      <Questionnaire>
        <QuestionnaireTitle id="questionnaire-meeting">How long should the meeting be?</QuestionnaireTitle>
        <QuestionnaireOptions aria-labelledby="questionnaire-meeting">
          {["15 minutes", "30 minutes", "1 hour"].map((length) => (
            <QuestionnaireOption key={length} selected={length === "30 minutes"} disabled>
              {length}
            </QuestionnaireOption>
          ))}
        </QuestionnaireOptions>
        <QuestionnaireDescription>Answer sent. You chose 30 minutes.</QuestionnaireDescription>
      </Questionnaire>
    </div>
  )
}

Long options

Stack long answers so they wrap. Options fill the width and wrap their text instead of truncating. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import {
  Questionnaire,
  QuestionnaireOption,
  QuestionnaireOptions,
  QuestionnaireTitle,
} from "@/components/ui/questionnaire"

export function QuestionnaireLongOptions() {
  return (
    <div className="flex w-full max-w-md flex-col gap-8">
      <Questionnaire className="max-w-xs">
        <QuestionnaireTitle id="questionnaire-report">Which report should I prepare first?</QuestionnaireTitle>
        <QuestionnaireOptions aria-labelledby="questionnaire-report" className="flex-col items-stretch">
          {[
            "Monthly revenue by region, compared with the same month last year",
            "Open support tickets older than seven days",
            "Hiring pipeline by team",
          ].map((report) => (
            <QuestionnaireOption key={report} className="rounded-12 text-left">
              {report}
            </QuestionnaireOption>
          ))}
        </QuestionnaireOptions>
      </Questionnaire>
    </div>
  )
}

API reference

Generated from the component's TypeScript signatures. Inherited DOM and primitive props are listed separately.

Questionnaire

The structured question an assistant asks mid-conversation: a prompt and a small set of answers that are quicker to tap than to type.

Questionnaire props
PropTypeDefaultDescription
inputMode"search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
childrenReact.ReactNode—Represents all of the things React can render.
Inherited props (13)
Questionnaire inherited props
PropTypeDefaultDescription
refReact.Ref<HTMLDivElement> | undefined—Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).
defaultCheckedboolean | undefined—Initial checked state for a control supporting uncontrolled selection. Inherited DOM typing does not give a layout wrapper checkbox behavior.
defaultValuestring | number | readonly string[] | undefined—Initial value for a control supporting uncontrolled state. Inherited DOM typing alone does not give a layout wrapper input behavior.
autoFocusboolean | undefined—Request automatic focus when the element mounts or the primitive opens, according to its source behavior. Choose initial focus deliberately in context.
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
roleReact.AriaRole | undefined—Semantic role appropriate to the rendered element. Preserve required relationships and keyboard behavior.
onFocusReact.FocusEventHandler<HTMLDivElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<HTMLDivElement> | undefined—Receive the native blur event when focus leaves this control.
onChangeReact.ChangeEventHandler<HTMLDivElement, Element> | undefined—Receive the native change event; read the actual control value or checked state from its event target.
onKeyDownReact.KeyboardEventHandler<HTMLDivElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<HTMLDivElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
onSelectReact.ReactEventHandler<HTMLDivElement> | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.

QuestionnaireDescription

Supporting text for this composition. Associate it with the relevant control when it conveys input help or errors.

QuestionnaireDescription props
PropTypeDefaultDescription
inputMode"search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
childrenReact.ReactNode—Represents all of the things React can render.
Inherited props (13)
QuestionnaireDescription inherited props
PropTypeDefaultDescription
refReact.Ref<HTMLParagraphElement> | undefined—Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).
defaultCheckedboolean | undefined—Initial checked state for a control supporting uncontrolled selection. Inherited DOM typing does not give a layout wrapper checkbox behavior.
defaultValuestring | number | readonly string[] | undefined—Initial value for a control supporting uncontrolled state. Inherited DOM typing alone does not give a layout wrapper input behavior.
autoFocusboolean | undefined—Request automatic focus when the element mounts or the primitive opens, according to its source behavior. Choose initial focus deliberately in context.
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
roleReact.AriaRole | undefined—Semantic role appropriate to the rendered element. Preserve required relationships and keyboard behavior.
onFocusReact.FocusEventHandler<HTMLParagraphElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<HTMLParagraphElement> | undefined—Receive the native blur event when focus leaves this control.
onChangeReact.ChangeEventHandler<HTMLParagraphElement, Element> | undefined—Receive the native change event; read the actual control value or checked state from its event target.
onKeyDownReact.KeyboardEventHandler<HTMLParagraphElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<HTMLParagraphElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
onSelectReact.ReactEventHandler<HTMLParagraphElement> | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.

QuestionnaireFooter

Footer layout for supporting content or actions; consumers own the actions and their outcomes.

QuestionnaireFooter props
PropTypeDefaultDescription
inputMode"search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
childrenReact.ReactNode—Represents all of the things React can render.
Inherited props (13)
QuestionnaireFooter inherited props
PropTypeDefaultDescription
refReact.Ref<HTMLDivElement> | undefined—Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).
defaultCheckedboolean | undefined—Initial checked state for a control supporting uncontrolled selection. Inherited DOM typing does not give a layout wrapper checkbox behavior.
defaultValuestring | number | readonly string[] | undefined—Initial value for a control supporting uncontrolled state. Inherited DOM typing alone does not give a layout wrapper input behavior.
autoFocusboolean | undefined—Request automatic focus when the element mounts or the primitive opens, according to its source behavior. Choose initial focus deliberately in context.
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
roleReact.AriaRole | undefined—Semantic role appropriate to the rendered element. Preserve required relationships and keyboard behavior.
onFocusReact.FocusEventHandler<HTMLDivElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<HTMLDivElement> | undefined—Receive the native blur event when focus leaves this control.
onChangeReact.ChangeEventHandler<HTMLDivElement, Element> | undefined—Receive the native change event; read the actual control value or checked state from its event target.
onKeyDownReact.KeyboardEventHandler<HTMLDivElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<HTMLDivElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
onSelectReact.ReactEventHandler<HTMLDivElement> | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.

QuestionnaireOption

A pressed button rather than a checkbox: the answer is sent as a message, so it reads as an action and not as a form the user still has to submit.

QuestionnaireOption props
PropTypeDefaultDescription
inputMode"search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
childrenReact.ReactNode—Represents all of the things React can render.
selectedboolean | undefinedfalseWhether this option is selected. Exposes aria-pressed; the consumer updates the selection in response to activation.
Inherited props (18)
QuestionnaireOption inherited props
PropTypeDefaultDescription
refReact.Ref<HTMLButtonElement> | undefined—Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).
disabledboolean | undefined—Make the supported control unavailable through its native or primitive disabled semantics. This does not disable arbitrary child links.
formstring | undefined—ID of the form associated with this control, including when it is rendered outside that form element.
namestring | undefined—Name used by the control's form submission or primitive form integration.
type"button" | "submit" | "reset" | undefined—Native element or primitive mode defined by the source union. Choose a supported value; its meaning depends on the component.
valuestring | number | readonly string[] | undefined—Current value in the shape defined by the source type. For controlled interactive inputs, apply updates from the change callback.
defaultCheckedboolean | undefined—Initial checked state for a control supporting uncontrolled selection. Inherited DOM typing does not give a layout wrapper checkbox behavior.
defaultValuestring | number | readonly string[] | undefined—Initial value for a control supporting uncontrolled state. Inherited DOM typing alone does not give a layout wrapper input behavior.
autoFocusboolean | undefined—Request automatic focus when the element mounts or the primitive opens, according to its source behavior. Choose initial focus deliberately in context.
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
roleReact.AriaRole | undefined—Semantic role appropriate to the rendered element. Preserve required relationships and keyboard behavior.
onFocusReact.FocusEventHandler<HTMLButtonElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<HTMLButtonElement> | undefined—Receive the native blur event when focus leaves this control.
onChangeReact.ChangeEventHandler<HTMLButtonElement, Element> | undefined—Receive the native change event; read the actual control value or checked state from its event target.
onKeyDownReact.KeyboardEventHandler<HTMLButtonElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<HTMLButtonElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
onSelectReact.ReactEventHandler<HTMLButtonElement> | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.

QuestionnaireOptions

The QuestionnaireOptions part of questionnaire. Use it with the complete source composition and preserve its required parent context.

QuestionnaireOptions props
PropTypeDefaultDescription
inputMode"search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
childrenReact.ReactNode—Represents all of the things React can render.
Inherited props (13)
QuestionnaireOptions inherited props
PropTypeDefaultDescription
refReact.Ref<HTMLDivElement> | undefined—Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).
defaultCheckedboolean | undefined—Initial checked state for a control supporting uncontrolled selection. Inherited DOM typing does not give a layout wrapper checkbox behavior.
defaultValuestring | number | readonly string[] | undefined—Initial value for a control supporting uncontrolled state. Inherited DOM typing alone does not give a layout wrapper input behavior.
autoFocusboolean | undefined—Request automatic focus when the element mounts or the primitive opens, according to its source behavior. Choose initial focus deliberately in context.
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
roleReact.AriaRole | undefined—Semantic role appropriate to the rendered element. Preserve required relationships and keyboard behavior.
onFocusReact.FocusEventHandler<HTMLDivElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<HTMLDivElement> | undefined—Receive the native blur event when focus leaves this control.
onChangeReact.ChangeEventHandler<HTMLDivElement, Element> | undefined—Receive the native change event; read the actual control value or checked state from its event target.
onKeyDownReact.KeyboardEventHandler<HTMLDivElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<HTMLDivElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
onSelectReact.ReactEventHandler<HTMLDivElement> | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.

QuestionnaireTitle

Visible title for this composition. Overlay titles also supply its accessible name when connected by the underlying primitive.

QuestionnaireTitle props
PropTypeDefaultDescription
inputMode"search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
childrenReact.ReactNode—Represents all of the things React can render.
Inherited props (13)
QuestionnaireTitle inherited props
PropTypeDefaultDescription
refReact.Ref<HTMLParagraphElement> | undefined—Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).
defaultCheckedboolean | undefined—Initial checked state for a control supporting uncontrolled selection. Inherited DOM typing does not give a layout wrapper checkbox behavior.
defaultValuestring | number | readonly string[] | undefined—Initial value for a control supporting uncontrolled state. Inherited DOM typing alone does not give a layout wrapper input behavior.
autoFocusboolean | undefined—Request automatic focus when the element mounts or the primitive opens, according to its source behavior. Choose initial focus deliberately in context.
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
roleReact.AriaRole | undefined—Semantic role appropriate to the rendered element. Preserve required relationships and keyboard behavior.
onFocusReact.FocusEventHandler<HTMLParagraphElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<HTMLParagraphElement> | undefined—Receive the native blur event when focus leaves this control.
onChangeReact.ChangeEventHandler<HTMLParagraphElement, Element> | undefined—Receive the native change event; read the actual control value or checked state from its event target.
onKeyDownReact.KeyboardEventHandler<HTMLParagraphElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<HTMLParagraphElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
onSelectReact.ReactEventHandler<HTMLParagraphElement> | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.

Accessibility & usage

From registry/ui/questionnaire.meta.json (authored guidance; human review may still be pending). Behavior is checked by Storybook tests, not certified here.

When to use

  • An assistant or support flow needs one piece of information with a small, known set of answers.
  • Clarifying questions mid-conversation ('Which plan is this about?') where typing would be slower.
  • Choose-several questions where the answer is sent as one message after selection.

When not to use

  • Forms with several fields, validation or persistence; use a form with proper controls.
  • A required single choice inside a form that is submitted later; a radio group gives native one-of-many semantics and arrow-key navigation.
  • More than about six options, or options that need descriptions; use a select, combobox or list.

Anatomy

Questionnaire
The bounded surface, up to a medium width, holding the question and its answers.
QuestionnaireTitle
The question as a paragraph; give it an id to name the options group.
QuestionnaireDescription
Hint or confirmation text ('Choose all that apply', 'Answer sent').
QuestionnaireOptions
A role="group" wrapper that wraps options onto several lines; needs aria-labelledby or aria-label.
QuestionnaireOption
A native button (type button by default) with aria-pressed from selected and a check icon when selected; disabled is native.
QuestionnaireFooter
Row for skip, send or continue actions owned by the consumer.

Keyboard & interaction

  • Each option is its own tab stop and activates with Enter or Space; aria-pressed reports whether it is selected.
  • There is no arrow-key navigation and no automatic exclusivity: the consumer sets selected on one option (single choice) or several (multiple choice).
  • Activating an option does not send anything; the consumer decides whether a tap sends immediately or a footer action confirms.
  • Disabled options are skipped by Tab and keep their selected appearance, which suits answered questions.

Responsive behavior

  • Options wrap onto several lines; for long answers, stack them in a column so each takes the full width.
  • Option buttons are about 32 CSS pixels tall; keep at least 24x24 and leave gaps between them for touch.
  • The surface takes the conversation width up to its maximum; footer actions align to the end and wrap if needed.

Content guidelines

  • Ask one question in plain words; put any instruction ('Choose all that apply') in the description.
  • Keep answers short, parallel and mutually clear; offer 'Something else' or 'Skip' when the list may not fit.
  • Name footer actions by what happens next ('Send answers', 'Continue'), and disable them until an answer is chosen when one is required.
  • After sending, confirm the chosen answer in text and make the question read-only.

Alternatives

  • Radio group — A form-field single choice with arrow-key navigation and automatic exclusivity.
  • Toggle group — A set of pressed options that changes a view or setting immediately.
  • Form — Several fields with labels, validation and submission.

Resources