shadcn.io is not affiliated with official shadcn/ui
Multi-Language FAQ Block for React
An FAQ in English, Spanish and Arabic for a relocation service: a language switcher swaps the title, questions and answers, and sets lang and dir so Arabic lays the block out from its end.
Installation
Overview
A multi-language FAQ for React with Base UI. A start-aligned header sits over a band holding a language switcher, English, Español and العربية, and six accordion rows that run from rail to rail under a rule with + marks. Choosing a language swaps the title, the sentence, every question and every answer, all written once in each language, and sets lang and dir on the block's region: Arabic lays the header and the rows out from the end, with the plus signs at the start, while the switcher keeps its order and place so it never moves under the pointer. The open question stays open. It's built from Accordion, Segment Group, Direction Provider and Guides, with CSS transitions for the entrance and your theme's tokens for every colour. For product and service pages with visitors in more than one language.
FAQ
How do I add or change a language?
Each entry of LANGUAGES holds one language: its code, dir (ltr or rtl), the label shown in the switcher in that language, the title and sentence, and the questions with their id, question and answer. Add an entry with the same question ids and the switcher grows by one segment. Keep the order of ids the same in every language, and have each translation read by a native speaker before you ship it: these are written as examples.
How does right-to-left work?
The region carries dir and lang for the chosen language, and the whole block is built with logical classes (ps-, text-start, border-e), so it mirrors on its own. The catalog's Direction Provider also tells the components inside it which way to read. The switcher sits in its own left-to-right box and keeps its order, with each label tagged with its own lang, so a screen reader pronounces "Español" and "العربية" correctly.
What happens to the open question when the language changes?
It stays open: the accordion isn't remounted, and every language uses the same ids. If you change OPEN_QUESTION, use an id that exists in every language.
Are all the languages in the page's markup?
Yes, but only one is shown. The three languages share one grid cell: the chosen one is visible, and the others are invisible, hidden from the accessibility tree and inert, so a screen reader and the Tab key only meet the language on screen. That keeps the block exactly as tall as its tallest language, so switching never moves what is below it. It also means search engines see all three. For separate pages per language, give each its own URL and render one language per page; this block is for switching in place.
How does the switcher work with a keyboard and a screen reader?
It's a group named "Language" with three options; the arrow keys move between them and the choice applies at once. The questions are buttons in h3 headings, and Enter or Space opens one.
Tab alone moves between questions on this library: its accordion doesn't take arrow keys.
Related
- 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
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
Topic Select FAQ
Topics and filtersA short FAQ for a bike-share with a topic Select at the end of its header: choose a topic and its questions fill the rows below, or choose All topics for all twelve.
- Pro
Compact FAQ
Accordion listsA dense FAQ for ski-lift passes: ten tight accordion rows with small type and one-sentence answers in a narrow framed list, a chevron at the start of each row.
- Pro
Numbered FAQ
Accordion listsA numbered FAQ for a wine club: eight accordion rows from rail to rail, with a margin of tabular numerals, 01 to 08, behind a hairline; the open row's numeral turns to full strength.
- Pro
Print-Friendly FAQ
Reading and sharingAn FAQ you can take on the trail, for a park visitor service: eight accordion rows, a Print this FAQ button and real print styles that open every answer and drop the controls.