Capítulo 9 de 43
A vertically (or horizontally) stacked set of interactive headings that each reveal an associated content panel, supporting single- or multi-item expansion.
Root → Item → Header (wraps Trigger) → Content.type prop ("single" | "multiple"): controls whether one or many items can be open at once.collapsible: when true and type="single", allows the currently open item to close, leaving none open.--radix-accordion-content-width/--radix-accordion-content-height: CSS variables exposing measured content size, used to animate open/close height without height: auto limitations.import { Accordion } from "radix-ui";
export default () => (
<Accordion.Root type="single" collapsible>
<Accordion.Item value="item-1">
<Accordion.Header>
<Accordion.Trigger>Trigger text</Accordion.Trigger>
</Accordion.Header>
<Accordion.Content>…</Accordion.Content>
</Accordion.Item>
</Accordion.Root>
);
| Part | Key props | Key data attributes |
|---|---|---|
Root | type*, value/defaultValue, collapsible, disabled, dir, orientation | [data-orientation] |
Item | value*, disabled | [data-state], [data-disabled], [data-orientation] |
Header | asChild (use to set correct heading level, e.g. h3) | [data-state], [data-orientation] |
Trigger | asChild | [data-state], [data-disabled], [data-orientation] |
Content | forceMount | [data-state], [data-orientation] |
Header's asChild to render the correct semantic heading level (h2/h3/etc.) for the page — Radix doesn't assume one.--radix-accordion-content-* CSS variables instead of max-height hacks or JS measurement.orientation.