Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Toggle All FAQ Block for React

A FAQ for a payroll app with Expand all and Collapse all buttons and a live open count above eight independent hairline rows.

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

An expand-all FAQ for React with Base UI. A title and one sentence sit above a toolbar band that carries a live count ("1 of 8 open") at the start and two ghost buttons, Expand all and Collapse all, at the end, with eight questions in hairline rows beneath it. Rows open and close independently, a turning chevron shows each one's state, and each toolbar button greys out when pressing it would change nothing. The rows run from rail to rail and the last one ends the block, so the next section's rule is its bottom edge. 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, Button and Guides, with CSS transitions for the entrance and your theme's tokens for every colour. For help pages and docs where visitors want to scan every answer at once, or print the page open.

FAQ

How do I change the questions?

Edit QUESTIONS at the top of the file: each entry is an id, the question and its answer, one to three sentences. ALL is built from the same list, so Expand all always opens every question you've written, and the count always reads from it. OPEN_QUESTION names the one that's open on load; set it to an id that doesn't exist to start with all of them closed.

How do the two buttons work?

The block keeps the list of open questions in state and gives it to the Accordion, so a row opened by hand and a row opened by Expand all are the same thing. Expand all sets the list to every id, Collapse all to none, and the count above them ("3 of 8 open") is a polite status line that announces the new number to a screen reader. The Accordion takes multiple, so any number of rows stay open together.

Why do the buttons grey out instead of being disabled?

They carry aria-disabled rather than disabled. A button that is really disabled drops keyboard focus the moment it's pressed (Expand all is pressed and then has nothing left to do), so focus would fall to the top of the page. With aria-disabled it keeps focus, looks and reads as unavailable, and pressing it again does nothing.

Are the closed answers in the page's markup?

Yes. The Accordion takes hiddenUntilFound, so every closed answer stays in the markup as hidden="until-found": search engines see all eight, and the browser's find in page opens the answer that holds a match.

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

Each question is a button inside its own h3 under the section's h2. Tab moves from the two toolbar buttons to the questions, Enter or Space opens and closes one, and every button says whether it's expanded. After Expand all or Collapse all, focus stays on the button you pressed.

How does it fit on a phone?

Below the sm breakpoint the count sits above the two buttons, both of which stay full size for touch, and the rows run from rail to rail with the chevron at their end. A question that doesn't fit wraps onto a second line, the answers drop to a smaller size, and nothing scrolls sideways at 320 pixels.

  • Pro

    Accordion FAQ

    Accordion lists

    A side-header FAQ for a web analytics tool: the title, one sentence and a contact prompt beside seven questions in an accordion, behind a split divider.

  • Pro

    Multi Select FAQ

    Topics and filters

    A topic-chip FAQ for an outdoor-gear rental: any number of chips can be on, and the list shows the union of their questions, with a live count.

  • Pro

    A two-level FAQ for a photo-book shop: an accordion of three sections whose panels each hold an accordion of questions, with a summary of how many of each.

  • Pro

    Collapsible Groups FAQ

    Accordion lists

    A 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

    A FAQ for a meal-kit service where every question shows its one-line answer and a Details button opens the longer one: a short list and a note.

  • Pro

    Minimal FAQ

    Cards and grids

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