Skip to content
Sign upPro
BlocksFAQMenu

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.

Five questions, then a row for anything else. An asked question stays in the list and its answer streams in beneath it.

Installation

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

Usage

tsx
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.

tsx
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

Stacked panels with numbers, so an asked question reads as the next one.

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

The small size beside an app, with several answers open at once.

Landing page

The large size on a pricing page, with no ask row.

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

Thinking, streaming, answered, stopped and failed.

Props

PropTypeNotes
itemsFaqItem[]{ id, question, answer, links? }
title, descriptionReactNodeThe 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
numberedbooleanNumbers every row
type"single" | "multiple"How many answers stay open. Defaults to single
value, defaultValue, onValueChangestring[]Open ids, controlled or not
linkableboolean#faq-<id> opens a question; open answers get Copy link
onAsk(question: string) => voidShows the ask row
askedFaqAsked[]{ id, question, status, answer?, activity?, links?, error? }
onStop, onRetry(id: string) => voidStop a streaming answer, retry a failed or stopped one
question, defaultQuestion, onQuestionChangestringThe ask input, controlled or not
suggestbooleanAnswered above suggestions. Defaults to true
disabledbooleanDisables the ask row
labelsPartial<FaqLabels>Every string, for translation

Keyboard

KeyAction
Enter or SpaceOpen or close the focused question
ArrowDown, ArrowUpNext or previous question
Home, EndFirst or last question
Enter in the ask rowAsk
Escape in the ask rowStop the answer

Accessibility

  • Each question is a button inside a heading one level below the title, with aria-expanded and 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-busy while 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.