Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Keyboard Navigation FAQ Block for React

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.

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 keyboard-first FAQ for React with Base UI. A header and eight numbered questions in hairline rows take the wide column; a framed legend of the keys sits in a narrow column at the end behind a split divider. The Up and Down arrows move between the questions, wrapping at both ends, Home and End jump to the first and last, and Enter or Space opens one; the block adds those keys itself wherever the accordion doesn't. The focused row is tinted with a strong ring, the legend lights the row of the key you're pressing and says which question has focus. On a tablet the legend sits under the list, and on a phone, with no keyboard, it's hidden. It's built from Accordion, Kbd and Guides, with CSS transitions for the entrance and your theme's tokens for every colour. For developer tools, admin panels and any product whose users keep their hands on the keys.

FAQ

How do I change the questions and the legend?

Edit QUESTIONS at the top of the file: each entry is an id, the question and its answer. The numbers in front are drawn from the position, so reordering renumbers them. The legend reads SHORTCUTS: each is a label, the caps drawn on the keys and the keys (as KeyboardEvent.key values) that light it.

How does the keyboard navigation work?

A handler on the list's wrapper hears the keys that bubble up from the question buttons. For the Up and Down arrows, Home and End it moves focus to the right button, wrapping at the ends, unless the accordion already did: it checks whether the key was prevented, so a key is never handled twice. Enter and Space are the buttons' own. This accordion has no arrow-key navigation of its own, so the block's handler provides it: the same keys, the same wrapping.

What does the legend do?

It lists the keys and lights the row of the one you press, for as long as it's held, and says "Question 3 of 8" for the row that has focus. It's decorative: the keys work the same without it, and a screen reader doesn't read the live line, because it already hears the focus move. It is hidden below md, where there's usually no keyboard.

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

Can I see where focus is?

Yes. The focused question gets a muted background and a three-pixel ring inside its row, drawn for keyboard focus only, so a click doesn't leave a mark. The ring stays visible in every theme, because it uses the theme's ring colour.

How does it work with a screen reader?

Each question is a button inside its own h3 under the section's h2, so the headings list shows all eight, and the button says whether it's expanded. The key legend is a list with a name, so its content can be read, and it carries no information the page needs.

  • 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

    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

    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

    Split View FAQ

    Navigation

    A master-detail FAQ for a sales CRM: a list of eight questions at the start and the chosen answer in a framed panel at the end, with a Next question button.

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