# Accordion

- **Section:** Components
- **URL:** https://refast.fastapicloud.dev/docs/components/accordion
- **Markdown:** https://refast.fastapicloud.dev/docs/components/accordion.md
- **Source:** https://github.com/idling-mind/refast-docs/blob/main/docs/pages/components/data_display/accordion.py
- **Live examples:** the widgets on this page need a browser; open the URL above to try them.
- **Applies to:** refast 0.12.2

Vertically stacked collapsible sections. Ideal for FAQs, settings panels,
and any content that benefits from progressive disclosure.

```python
from refast.components import Accordion, AccordionItem, AccordionTrigger, AccordionContent

Accordion(
    type="single",
    collapsible=True,
    children=[
        AccordionItem(
            value="q1",
            children=[
                AccordionTrigger(children=["Is it accessible?"]),
                AccordionContent(children=[Text("Yes. It adheres to WAI-ARIA.")]),
            ],
        ),
    ],
)
```

Is it accessible?

Yes. It adheres to the WAI-ARIA design pattern for accordions.

Is it styled?

Yes. It comes with default styles that match the shadcn/ui design system.

Is it animated?

Yes. It uses CSS transitions to animate the open/close state smoothly.

```python
Accordion(
    type="single",
    collapsible=True,
    children=[
        AccordionItem(value="item-0", children=[
            AccordionTrigger(children=["Is it accessible?"]),
            AccordionContent(children=[Text("...")]),
        ]),
        AccordionItem(value="item-1", children=[
            AccordionTrigger(children=["Is it styled?"]),
            AccordionContent(children=[Text("...")]),
        ]),
        AccordionItem(value="item-2", children=[
            AccordionTrigger(children=["Is it animated?"]),
            AccordionContent(children=[Text("...")]),
        ]),
    ],
)
```

## Accordion Props

| Prop | Type | Default | Description |
|------|------|---------|-------------|
| `children` | `list` | `[]` | `AccordionItem` components. |
| `type` | `"single" \| "multiple"` | `"single"` | `"single"` allows one item open; `"multiple"` allows many. |
| `collapsible` | `bool` | `True` | When `type="single"`, allows closing all items. |
| `default_value` | `str \| list[str] \| None` | `None` | Initially open item(s) (uncontrolled). |
| `value` | `str \| list[str] \| None` | `None` | Controlled open item(s). |
| `on_value_change` | `Callback \| None` | `None` | Fired when open items change. `ctx.event_data` is `{"value": ...}`. |
| `class_name` | `str` | `""` | Extra Tailwind classes. |

## AccordionItem Props

| Prop | Type | Default | Description |
|------|------|---------|-------------|
| `value` | `str` | *(required)* | Unique identifier within the accordion. |
| `children` | `list` | `[]` | One `AccordionTrigger` and one `AccordionContent`. |
| `class_name` | `str` | `""` | Extra Tailwind classes. |

## AccordionTrigger / AccordionContent Props

| Prop | Type | Default | Description |
|------|------|---------|-------------|
| `children` | `list` | `[]` | Trigger label text or content to reveal. |
| `class_name` | `str` | `""` | Extra Tailwind classes. |

## Multiple open items

```python
Accordion(
    type="multiple",
    default_value=["item-1", "item-3"],
    children=[
        AccordionItem(value="item-1", children=[
            AccordionTrigger(children=["Section 1"]),
            AccordionContent(children=[Text("Content 1")]),
        ]),
        AccordionItem(value="item-2", children=[
            AccordionTrigger(children=["Section 2"]),
            AccordionContent(children=[Text("Content 2")]),
        ]),
        AccordionItem(value="item-3", children=[
            AccordionTrigger(children=["Section 3"]),
            AccordionContent(children=[Text("Content 3")]),
        ]),
    ],
)
```

## Controlled accordion

```python
async def on_change(ctx: Context):
    ctx.state.set("open_items", ctx.event_data.get("value"))
    await ctx.refresh()

def render(ctx: Context):
    open_items = ctx.state.get("open_items", [])
    return Accordion(
        type="multiple",
        value=open_items,
        on_value_change=ctx.callback(on_change),
        children=[...],
    )
```

---

Part of the Refast documentation: [all pages](https://refast.fastapicloud.dev/llms.txt), [everything on one page](https://refast.fastapicloud.dev/llms-full.txt), [search](https://refast.fastapicloud.dev/api/search?q=save_prop).
