FAQ
Questions and answers, with a last row where anyone can ask their own. An asked question stays in the list as a row of its own, its answer streaming in beneath it.
On this page
Installation
Usage
import { Faq } from "@/components/ui/chatcn/faq"
<Faq
title="Questions"
description="The short ones are here. For anything else, ask below."
items={[
{
id: "self-host",
question: "Can I self-host it?",
answer: "Yes. Run the agent in your own cluster and raw logs never leave your network.",
links: [{ label: "Self hosting", href: "/docs/self-hosting" }],
},
]}
/>Without onAsk it is a plain FAQ: one answer open at a time (type="multiple" keeps several open), the open ids controlled through value and onValueChange or left to defaultValue. A string answer renders as paragraphs split on blank lines; pass any node for links, lists or code.
Let people ask
Pass onAsk and the last row becomes an input in the exact footprint of a question: the placeholder sits where a question sits and the send arrow where the chevrons are, so focusing it moves nothing. Send a question and it stays where it was typed, as a new row with its answer opening beneath it, and a fresh ask row appears under it. The list grows by what people ask.
const [asked, setAsked] = React.useState<FaqAsked[]>([])
<Faq
items={items}
asked={asked}
onAsk={(question) => {
const id = crypto.randomUUID()
setAsked((list) => [...list, { id, question, status: "submitted", activity: "Reading the docs" }])
streamAnswer(question, {
onText: (answer) => update(id, { status: "streaming", answer }),
onDone: (links) => update(id, { status: "done", links }),
onError: () => update(id, { status: "error", error: "The answer could not load. Retry in a moment." }),
})
}}
onStop={(id) => update(id, { status: "stopped" })}
onRetry={(id) => retry(id)}
/>Each asked entry carries its own status. While it is submitted nothing shows for 300 ms, then activity (or Thinking) with the text shimmer. The answer is Markdown and streams with the kit caret; when it is done its links show as sources with a note that the answer was written by AI. Stop sits in the send button's footprint while an answer streams, and Escape does the same. While someone types, questions that already answer theirs appear under the row as Answered above, and picking one opens it.
Examples
Cards, numbered
variant="cards" gives every question its own panel. numbered counts every row, asked ones included, and shows the next number on the ask row, so a question someone asks reads as the next one in the list.
Help panel
Landing page
layout="split" (the default) puts the heading beside the list once the component is wider than 48 rem, and keeps it in view while the list scrolls. Narrower, it stacks. Sizes: sm for help panels, md for docs, lg for landing pages.
Asked states
Props
| Prop | Type | Notes |
|---|---|---|
items | FaqItem[] | { id, question, answer, links? } |
title, description | ReactNode | The heading. headingLevel sets its level, 2 by default |
layout | "split" | "stacked" | Defaults to split |
variant | "lines" | "cards" | Defaults to lines |
size | "sm" | "md" | "lg" | Defaults to md |
numbered | boolean | Numbers every row |
type | "single" | "multiple" | How many answers stay open. Defaults to single |
value, defaultValue, onValueChange | string[] | Open ids, controlled or not |
linkable | boolean | #faq-<id> opens a question; open answers get Copy link |
onAsk | (question: string) => void | Shows the ask row |
asked | FaqAsked[] | { id, question, status, answer?, activity?, links?, error? } |
onStop, onRetry | (id: string) => void | Stop a streaming answer, retry a failed or stopped one |
question, defaultQuestion, onQuestionChange | string | The ask input, controlled or not |
suggest | boolean | Answered above suggestions. Defaults to true |
disabled | boolean | Disables the ask row |
labels | Partial<FaqLabels> | Every string, for translation |
Keyboard
| Key | Action |
|---|---|
Enter or Space | Open or close the focused question |
ArrowDown, ArrowUp | Next or previous question |
Home, End | First or last question |
Enter in the ask row | Ask |
Escape in the ask row | Stop the answer |
Accessibility
- Each question is a button inside a heading one level below the title, with
aria-expandedand the answer as its controlled region. - On Base UI, closed answers use
hidden="until-found", so find in page reaches them and opens the question. - A finished asked answer is announced once through a polite live region, never word by word, and the row is
aria-busywhile it streams. - The send button is labelled Ask, and Stop answering while an answer streams. Its hit area is 32 px around the 24 px mark.
Motion
- Answers open in 200 ms and close in 150 ms with the kit ease out; the chevron turns at the click.
- A fresh ask row fades in after a question is sent. Nothing moves when the row is focused or typed into.
- Reduced motion keeps the fades and drops the height change.