Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Command Palette FAQ Block for React

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.

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 FAQ with a working command palette for React with Base UI. A start-aligned header sits over a band holding a button that looks like a search field, with its shortcut at the end, and nine questions in hairline rows, each with its topic beside it. The button opens a palette in a dialog that lists the questions grouped by topic; filter by typing, pick one, and the palette closes, that row opens below and focus moves to it. The shortcut, Command K on a Mac and Control K elsewhere, opens it too, but only while the block is on the page. 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, Command, Kbd, Button and Guides, with CSS transitions for the entrance and your theme's tokens for every colour. For developer docs and product pages whose readers live on the keyboard.

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 palette's groups are the topics in the order they first appear, and the count in the button and the header comes from the array. Nine questions suit a short page; the palette comfortably holds fifty.

How does the shortcut work?

While the block is mounted, a keydown listener opens the palette on Command K or Control K and stops the browser's own handling. It reads "Ctrl K" in the markup and switches to "⌘ K" once the page knows it's running on a Mac, so server rendering and hydration agree. On a phone the shortcut hint is hidden, because there is no keyboard to press it on; the button still opens the palette.

Where does focus go when I choose a question?

To the question's button in the list, with its answer open, so a keyboard user lands where they chose. If you close the palette with Escape instead, focus returns to whatever opened it: the button, or the element that had focus when you pressed the shortcut. The block waits a beat after the dialog closes and then focuses the row, because the dialog hands focus back to the opener first.

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" and the browser's find in page opens the one that holds a match.

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

The button is named "Search 9 questions" and announces its shortcut, the palette is a dialog with a labelled field and a list you move through with the Up and Down arrows, Enter opens the highlighted question and Escape closes. In the list, each question is a button inside its own h3 under the section's h2; Tab moves between them and Enter or Space opens one.

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

  • Pro

    A keyboard-first FAQ for a text editor: eight questions that move with the arrow keys, Home and End, beside a framed legend of the keys that lights the one you press.

  • Pro

    A showcase hero for a keyboard-first issue tracker: a centred headline and two calls to action over a command palette drawn in a hairline frame.

  • Pro

    A centred card-in-card call to action built around a keyboard shortcut: three key caps in a hairline frame that press down as the keys do and open a filterable command palette, which the Shine Button opens too.

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