Data displayFaqItem
Searchastronomic.dev# FaqItem
For one question and its answer in a Faq section. The faq recipes use it for you.
Static: no JavaScript.
## Usage
```astro
import FaqItem from "@astronomic/ui-pro/components/FaqItem.astro";
```
## Examples
### In a Faq section
Two questions in a Faq section: one open, with an answer in two paragraphs, one closed. The faq recipes build their questions from it, so you only need it for your own layout.
```astro
---
import { childHeadingTag } from "@astronomic-dev/ui/lib/heading.ts";
import Faq from "@astronomic/ui-pro/components/Faq.astro";
import FaqItem from "@astronomic/ui-pro/components/FaqItem.astro";
const heading = "Questions";
const tag = childHeadingTag({ heading });
---
<div class="mx-auto max-w-3xl">
<Faq heading={heading}>
<FaqItem
question="What do you need from us to start?"
answer={[
"A short brief, a contact who can make decisions, and any brand material you already have.",
"We write the first draft of the copy with you, so you do not need finished text.",
]}
headingTag={tag}
open
/>
<FaqItem question="A closed question" answer="Its answer shows when the question is opened." headingTag={tag} />
</Faq>
</div>
```
## Props
### FaqItem
| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `question` | `string` | None | Required. The question, in the heading role in display type, inside the summary. |
| `answer` | `string \| string[]` | None | Required. One answer, or a list of paragraphs, in the body role, muted, at the running-text width (max-w-prose). |
| `headingTag` | `"h2" \| "h3" \| "h4" \| "h5"` | None | Required. The question element. Pass childHeadingTag({ heading, headingTag }) from lib/heading.ts, one level under the section heading. |
| `open` | `boolean` | `false` | Open on load. |
| `name` | `string` | None | The group: questions that share a name open one at a time (the browser does it). The recipes pass one per list with single; give your own list one uid(). |
| `titleClass` | `string` | None | Classes for the question, after its own, so yours win: such as your theme's type role (text-subhead). |
| `iconClass` | `string` | None | Classes for a box around the open and close icon (data-faq-icon), such as a 44px round frame centered on the question: size-11 self-center rounded-full border-ui border-solid border-fg/30. The box takes the icon's color (muted unless you set one); the icon keeps its size and turns to point up when open. Without it the icon sits bare beside the question's first line. |
| `class` | `string` | None | More classes for the <details>, merged with cn(), so yours win on conflicts. A hairline sits above each question and below the last. |
Any other attribute goes on the <details>.
## Accessibility
- Renders one native <details> and <summary>: Enter or Space opens and closes it, with no script.
- The question is the heading level you pass. Use childHeadingTag so it sits one level under the section heading.
- Do not put links or other controls in the question: the whole summary is the control.
- The chevron icon is hidden from a screen reader; the summary says whether it is open.
FaqItem
ProFor one question and its answer in a Faq section. The faq recipes use it for you.
- File
- FaqItem.astro
- Group
- Data display
- Kind
- Static: no JavaScript
- Examples
- 1
Examples
Drag the orange handle to set the width. Frames get real breakpoints.
- Static
- Interactive
- Framed
In a Faq section
Two questions in a Faq section: one open, with an answer in two paragraphs, one closed. The faq recipes build their questions from it, so you only need it for your own layout.
Questions
What do you need from us to start?
A short brief, a contact who can make decisions, and any brand material you already have.
We write the first draft of the copy with you, so you do not need finished text.
A closed question
Its answer shows when the question is opened.
Force statemain.astro
examples/faqitem/main.astro
---
import { childHeadingTag } from "@astronomic-dev/ui/lib/heading.ts";
import Faq from "@astronomic/ui-pro/components/Faq.astro";
import FaqItem from "@astronomic/ui-pro/components/FaqItem.astro";
const heading = "Questions";
const tag = childHeadingTag({ heading });
---
<div class="mx-auto max-w-3xl">
<Faq heading={heading}>
<FaqItem
question="What do you need from us to start?"
answer={[
"A short brief, a contact who can make decisions, and any brand material you already have.",
"We write the first draft of the copy with you, so you do not need finished text.",
]}
headingTag={tag}
open
/>
<FaqItem question="A closed question" answer="Its answer shows when the question is opened." headingTag={tag} />
</Faq>
</div>Minimal · Light