# Questionnaire

> A step-by-step form with text, single and multiple choice.

- Category: [App & chat](https://tarve.dev/docs.md#chat)
- Import: `import { Questionnaire } from "@tarve/core";`
- Props type: `QuestionnaireProps`
- Source: [packages/core/src/advanced-controls.ts:330](https://github.com/omarcosr/tarve/blob/main/packages/core/src/advanced-controls.ts#L330)

## Usage

```tsx title="Questionnaire.tsx"
import { Questionnaire, type QuestionnaireAnswer } from "@tarve/core";

let current = 0;
let values: Record<string, QuestionnaireAnswer | undefined> = { name: "Ada" };

<Questionnaire
  style={{ width: 440 }}
  current={current}
  values={values}
  questions={[
    { id: "name", title: "What's your name?", type: "text", required: true },
    {
      id: "runtime",
      title: "Favourite runtime?",
      type: "single",
      options: [
        { value: "bun", label: "Bun" },
        { value: "node", label: "Node" },
      ],
    },
  ]}
  onCurrentChange={(index) => {
    current = index;
  }}
  onValueChange={(id, value) => {
    values = { ...values, [id]: value };
  }}
  onSubmit={() => console.log(values)}
/>
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `current` (required) | `number` | — |  |
| `questions` (required) | `readonly QuestionnaireQuestion[]` | — |  |
| `values` (required) | `Readonly<Record<string, QuestionnaireAnswer \| undefined>>` | — |  |
| `nextLabel` | `string` | `"Next"` |  |
| `onCurrentChange` | `(index: number) => void` | — |  |
| `onSubmit` | `() => void` | — |  |
| `onValueChange` | `(questionId: string, value: QuestionnaireAnswer) => void` | — |  |
| `previousLabel` | `string` | `"Previous"` |  |
| `submitLabel` | `string` | `"Submit"` |  |

## Common props

Shared by every component (descriptions: https://tarve.dev/docs.md#common-props): `children`, `class`, `className`, `highlight`, `id`, `key`, `motionFrom`, `onHighlight`, `onPaste`, `onPointerLeave`, `onPointerMove`, `onSize`, `onTransitionEnd`, `rovingGroup`, `style`.

## Types

```ts title="QuestionnaireAnswer"
type QuestionnaireAnswer = string | string[];
```

```ts title="QuestionnaireQuestion"
interface QuestionnaireQuestion {
  id: string;
  title: string;
  description?: string;
  type: "text" | "single" | "multiple";
  options?: readonly RadioOption[];
  required?: boolean;
  placeholder?: string;
}
```

Previous: [Attachment](https://tarve.dev/docs/components/Attachment.md)

---

Tarve v0.13.8 · HTML version: https://tarve.dev/docs/components/Questionnaire · Index for agents: https://tarve.dev/llms.txt
