Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Floating Search FAQ Block for React

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

Framework
UI library

Preview

Preview width

Installation

Part of Pro
Pro unlocks the code and one-line install of every Pro button and text effect, plus the MCP for your AI editor.
Have Pro already? Sign in to open it.Opens here as soon as you're Pro.

Overview

A long FAQ for React with Base UI. A start-aligned header gives way to a search pill that sticks near the top of the screen as you scroll, so you can search from the last question as easily as from the first. Twelve questions sit in three topic bands, each with its title and count above hairline rows, and the pill carries a live count and a Clear button. Typing filters the questions by their words and their topic, hides the questions that don't match and the bands that end up empty, and the list keeps a floor height so the page doesn't jump. The page's rails and top rule come from the Guides spine, so the block lines up with its neighbours in a stack. It's built from Accordion, Input Group, Guides and Button, with CSS transitions for the entrance and your theme's tokens for every colour. For long pages of questions, such as travel, rental and booking help.

FAQ

How do I change the questions and topics?

Edit QUESTIONS at the top of the file: each entry is an id, its topic, the question and its answer. The bands are the topics in the order they first appear, with their counts computed from the array. Keep the questions in each band together, as the bands are drawn in that order.

How does the search stay in place?

The pill is position: sticky at top-2, inside the block's column, so it follows you down the list and stops at the end of the block. It works because no ancestor clips overflow on the vertical axis: the section only clips sideways, which sticky positioning allows. If you put the block inside a scroll container, the pill sticks to that container instead; give the container overflow: clip rather than hidden or auto to keep it sticking to the page.

What does the search match?

The question's words and its topic, ignoring case and accents, anywhere in them: "bike" and "on board" both find the bike question. It doesn't read the answers, so what you see in a row is what matched. To include them, add item.answer to the text compared in matches.

Does the page jump while I type?

No. The list has a floor height, so filtering to two questions leaves the space below intact; the pill's count is the only part that changes. If nothing matches, an empty state says "No questions match" with the typed words and a Clear search button that also returns focus to the field.

Are the closed answers in the page's markup?

Yes, until you search. The Accordions take hiddenUntilFound, so every closed answer stays in the markup as hidden="until-found". Questions that don't match a search are removed.

How does it work with a keyboard and a screen reader?

The field is named "Search the questions" and the pill's count is a polite status ("7 of 12"). The topic titles and the questions are all h3 headings under the section's h2, so a headings list shows the topics and every question. Tab moves from the field to the Clear button and down the questions; Enter or Space opens one. Each topic is its own accordion.

  • Pro

    A 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

    A 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

    Sticky Nav FAQ

    Navigation

    A sticky-nav FAQ for a web host: a horizontal topic bar that follows the page while four bands of always-open answers scroll under it.

  • Pro

    Categorized FAQ

    Topics and filters

    A topic-tabbed FAQ for a bookkeeping app: a compact header, a band of line tabs with a count on each, and one accordion per topic.

  • Pro

    Topic Select FAQ

    Topics and filters

    A short FAQ for a bike-share with a topic Select at the end of its header: choose a topic and its questions fill the rows below, or choose All topics for all twelve.

  • Pro

    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.