# Question Example

> Example implementation of question.

A shadcn/ui block from the [@ai-elements](https://ai-sdk.dev/elements) registry, listed on [shadcn.exchange](https://shadcn.exchange/r/ai-elements/example-question).

- Page, with a live preview: https://shadcn.exchange/r/ai-elements/example-question
- Screenshot: https://abzjhwgwpdpz7ua5.public.blob.vercel-storage.com/shots/ai-elements/example-question-light-c1988a7b2da30a3d.png
- Registry item: https://ai-sdk.dev/elements/api/registry/example-question.json
- Listed: 2026-10-14, source last changed 2026-10-14

## Install

```bash
npx shadcn@latest add https://ai-sdk.dev/elements/api/registry/example-question.json
```

Run it in a project that has shadcn/ui set up. It adds the files below and installs what they depend on.

## Dependencies

- Registry items: `https://elements.ai-sdk.dev/question.json`

## Files

### `registry/default/examples/question.tsx`

```tsx
"use client";

import type { QuestionResponse } from "@/components/ai-elements/question";

import {
  Question,
  QuestionActions,
  QuestionDescription,
  QuestionInput,
  QuestionOption,
  QuestionOptions,
  QuestionPrompt,
  QuestionSubmit,
} from "@/components/ai-elements/question";
import { useState } from "react";

const Example = () => {
  const [response, setResponse] = useState<QuestionResponse>();

  if (response) {
    const selected = response.selectedValues.join(", ");
    const summary = [selected, response.text].filter(Boolean).join(" — ");

    return (
      <div className="w-full max-w-2xl rounded-lg border bg-background p-4 text-sm">
        <span className="text-muted-foreground">Answered: </span>
        {summary}
      </div>
    );
  }

  return (
    <Question
      className="w-full max-w-2xl"
      onSubmit={setResponse}
      selectionMode="multiple"
    >
      <div className="space-y-1">
        <QuestionPrompt>What should the project include?</QuestionPrompt>
        <QuestionDescription>
          Choose any features and add details if needed.
        </QuestionDescription>
      </div>
      <QuestionOptions aria-label="Project features">
        <QuestionOption value="authentication">Authentication</QuestionOption>
        <QuestionOption value="database">Database</QuestionOption>
        <QuestionOption value="payments">Payments</QuestionOption>
      </QuestionOptions>
      <QuestionInput
        aria-label="Additional requirements"
        placeholder="Add any other requirements…"
      />
      <QuestionActions>
        <QuestionSubmit>Answer</QuestionSubmit>
      </QuestionActions>
    </Question>
  );
};

export default Example;
```
