shadcn.io is not affiliated with official shadcn/ui
Schema Inspector FAQ Block for React
A headless-CMS FAQ with a live schema inspector: six questions beside a sticky JSON tree of the FAQPage data that expands and highlights the open question, a button to copy the JSON and one JSON-LD script.
Installation
Overview
An FAQ for React with Base UI that shows its own structured data. A start-aligned header sits in a band over two columns: six questions as hairline rows at the start, and at the end, behind a split divider, a tinted panel with a sticky inspector. The inspector is a JSON tree of the FAQPage data with a button that copies it; opening a question expands its node in the tree and highlights it, and you can open and close the other nodes yourself. The tree, the copied text and the single application/ld+json script the block emits are all built from the same FAQS array, so they can't drift. On a phone the inspector sits under the questions behind a "View the schema" button. It's built from Accordion, JSON Tree View, Copy Button, Button and Guides. For docs, CMS and SEO pages where you want to show editors exactly what search engines read.
FAQ
Where does the structured data come from?
FAQS at the top of the file. A SCHEMA object is built from it once: a FAQPage with a Question for each entry and its acceptedAnswer. The tree draws that object, the Copy JSON button copies it pretty-printed, and the block's script tag carries it compact, with every < escaped as < so an answer can never close the tag. Answers should be plain text.
How does the tree follow the open question?
The tree names each node with a hash of its path, such as $.mainEntity.2, and the block computes the same hash with pathId to know which node is a question's. The open question's node is expanded and tinted with a ring; closing the question clears it. That hash is the tree's own detail: if a later version changes it, the tree keeps working and only the automatic expanding and highlighting stop.
Is the JSON coloured like an editor?
No. The tree's string, number and boolean tones are set to the theme's foreground, so it reads the same in every preset, light or dark; the keys are medium weight and the structure comes from indentation and the expand arrows. The tree keeps room for its tallest state, so opening a question never moves the page.
Are the closed answers in the page's markup?
Yes. The Accordion takes hiddenUntilFound, so closed answers stay 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?
Each question is a button inside its own h3 under the section's h2; the inspector's heading is an h3 too. The tree is a keyboard tree: Tab enters it and the arrow keys move between nodes, expanding and collapsing them, and each node has a label that says what it holds. The copy button announces "Copied" politely.
How does it fit on a phone?
Below the lg breakpoint the tinted panel goes under the questions, under a rule, with a ghost "View the schema" button that opens and closes the inspector (it's aria-expanded, and the inspector stays in the page either way). From lg the button is gone and the inspector stays in view as you scroll the list.
Related
- Pro
JSON-LD FAQ
Code and mediaA gift-shop FAQ that shows what its structured data is for: six questions beside a mock search result with an FAQ rich result, and one FAQPage JSON-LD script built from the same list.
- Pro
Code Snippet FAQ
Code and mediaAn SDK FAQ for a webhook service: five questions whose answers are code windows with curl, Node and Python tabs and a copy button, in a band of hairline rows.
- Pro
API Error Codes FAQ
Code and mediaAn error-code FAQ for a geocoding API: seven status codes as accordion rows with a mono chip, a cause, a fix, the header to look for and a retry verdict, beside a retry-rules note.
- Pro
Accordion FAQ
Accordion listsA 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
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
Diagram FAQ
Code and mediaA centred identity-service FAQ whose first answer carries a sequence diagram with three lifelines and four numbered arrows, driven by a list of steps you can hover, focus or press.