shadcn.io is not affiliated with official shadcn/ui
Sticky Nav FAQ Block for React
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.
Installation
Overview
A sticky-nav FAQ for React with Base UI. Under a compact header, a horizontal bar of four topic links sticks to the top of the screen while four bands scroll under it; each band names its topic at the start and lays its answers out as open questions and answers in a definition list, two across from sm. The topic in view is underlined as you scroll, a link jumps to its band and the band lands clear of the bar, and a contact band closes the block. The bar scrolls sideways when the links don't fit. It's built from Guides and Button, a nav with plain links and a definition list, with a small scroll listener for the underline and your theme's tokens for every colour. For reference pages where every answer should be visible and findable without opening anything.
FAQ
How do I change the topics and answers?
Edit TOPICS at the top of the file: each topic has an id, a label, a one-line blurb and its questions (an id, the question and a short answer). The bar's links, the bands and the underline all come from that list. Keep answers to a sentence: every answer is on the page at once, so a long one lengthens it.
Why doesn't the bar stick in my page?
A sticky element stops working when an ancestor between it and the page's scroll has overflow: hidden, auto or scroll. The block adds none (its section clips only horizontally, with overflow-x: clip, which is fine); if the bar doesn't stick, look for an overflow in your own layout, or in a wrapper that previews the block. It sticks at top-0: add the height of a fixed site header to top- and to the bands' scroll-mt-.
How does the underline know which topic I'm reading?
A scroll listener, added while the block is mounted, takes the last band whose top has passed the bar as the topic in view, and the last band once you reach the end of the page, where it may never get that far. The current link carries aria-current="location", so the underline isn't the only signal. A click on a link marks its topic at once.
How does it work with a keyboard and a screen reader?
The bar is a navigation landmark named "Topics" with plain links: Tab reaches them, Enter jumps to the band, and focus follows the jump. Each band is a section named by its h3, and its questions and answers are terms and descriptions in a definition list, so a screen reader reads each pair together.
Related
- Pro
Table of Contents FAQ
NavigationA FAQ for an object-storage service with a sticky table of contents: three topics and their questions in an outline that follows the reader, beside topic bands that each hold an accordion.
- Pro
Collapsible Groups FAQ
Accordion listsA grouped FAQ for a grocery-delivery service: four topic bands that collapse as a whole, each holding its questions as always-visible answers, the first two open.
- Pro
Side by Side FAQ
Cards and gridsAn always-open FAQ for a freight carrier: eight questions with their answers side by side in hairline rows, the question and topic at the start and the answer at the end.
- Pro
Categorized FAQ
Topics and filtersA 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
Minimal FAQ
Cards and gridsA type-forward FAQ for a stationery brand: six questions in large type with their answers on show in a definition list, no cards or row lines, and one contact link.
- Pro
Breadcrumb FAQ
NavigationA drill-down help centre for a mobile carrier: four topic cells in a framed card, a breadcrumb bar, and each topic's questions behind a click.