shadcn.io is not affiliated with official shadcn/ui
Answer Finder FAQ Block for React
An answer finder for a team writing tool on a card in card: describe a problem and the closest help article opens, quoted word for word, with two ranked articles to try.
Installation
Overview
An answer finder for React with Base UI. A muted shell with + marks on its corners wraps a raised panel that follows your theme: a labelled text area, a note that says answers are matched by keywords and not by a model, and the Shine Button. After a short wait with a typing indicator, the closest help article opens under the field as the answer, quoted word for word, with two more articles to try, each with a bar showing how close it is. It scores your words against twelve articles in plain code: there is no model behind it, and the copy says so. The result area keeps its height, and a closing line points to a human. It's built from Guides, Textarea, Shine Button, Button, Badge and Typing Indicator Text, with CSS transitions for the entrance and your theme's tokens for every colour. For help centres whose visitors describe a problem in their own words.
FAQ
How do I change the help articles?
Edit ARTICLES at the top of the file: each has an id, the question, its answer and keywords, the words people use for it that the question doesn't. The copy counts the articles from the array. EXAMPLES holds the three starting points shown before the first search.
How does the matching work?
rank splits your words, drops common ones, cuts each to a stem of five letters and scores every article: a stem in the question counts three, in the keywords two and in the answer one. The best article is the answer, and the next two are "Also try", each with a bar sized against the best one's score. That is all there is: no model, no network request, and the same words always give the same answer. To use a real search or model, replace rank and keep the rest.
Why is there a short wait?
So the change from a question to an answer is visible. THINKING is 600 milliseconds, and during it the result area shows a typing indicator and a screen reader hears "Reading 12 help articles". Set it to 0 to answer at once. With reduced motion the dots hold still, but the wait stays so the status is still heard.
Does the page jump when the answer appears?
No. The result area has a floor height tall enough for an answer with two articles, and it shows the starting points before the first search. A longer answer grows the card, but nothing above it moves.
Related
- Pro
Live Search FAQ
SearchA searchable FAQ for a notes app: a start-aligned header, a band with a full-width search field and a live count, and ten questions that filter as you type, open every match and mark the matched words.
- Pro
Command Palette FAQ
SearchA FAQ for a docs host with a working command palette: a search-field button with its shortcut opens a palette of questions by topic, and choosing one opens its row below.
- Pro
Chatbot-Style FAQ
Contact and signupAn FAQ you ask like a chat, for a local council: a chat window with six question chips that posts your choice, shows a typing indicator and replies with the FAQ's own answer.
- Pro
Split Search Bar Hero
Interactive demosA split hero whose call to action is a large search field with a Shine Button, popular searches, and, across a solid divider, a results panel that filters as you type.
- Pro
Centered Email Capture CTA
Forms and captureA call to action between solid rails that follows the page theme, in a card in card with a two-step email capture: an email field and a Shine Button, then a six-digit code that verifies on the sixth digit and turns into a confirmation in the same space.
- Pro
Floating Search FAQ
SearchA long FAQ for a ferry operator with a search pill that sticks to the top of the screen while twelve questions scroll past in three topic bands.