Collapsible
@peduarte starred 3 repositories
@peduarte starred 3 repositories
@radix-ui/primitives
@radix-ui/colors
@stitches/react
<details class="collapsible" style="width: 21rem"> <summary class="collapsible-trigger"> <div class="item" data-variant="outline"> <div class="item-content"> <span class="item-title">@peduarte starred 3 repositories</span> </div> <div class="item-actions"> <span class="btn btn-ghost btn-icon-sm"> <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"> <path d="m7 15 5 5 5-5M7 9l5-5 5 5"></path> </svg> <span class="sr-only">Toggle</span> </span> </div> </div> </summary>
<div class="collapsible-content" style="display: grid; gap: 0.5rem; padding-top: 0.5rem"> <div class="item" data-variant="outline" data-size="sm"> <div class="item-content"><span class="item-title">@radix-ui/primitives</span></div> </div> <div class="item" data-variant="outline" data-size="sm"> <div class="item-content"><span class="item-title">@radix-ui/colors</span></div> </div> <div class="item" data-variant="outline" data-size="sm"> <div class="item-content"><span class="item-title">@stitches/react</span></div> </div> </div></details><details class="collapsible"> <summary class="collapsible-trigger">…</summary> <div class="collapsible-content">…</div></details>| Class | Part |
|---|---|
.collapsible | The <details> element |
.collapsible-trigger | The <summary> that toggles it |
.collapsible-content | What is revealed |
The collapsible carries no look of its own — it only removes the disclosure marker and animates the height. Whatever goes inside keeps its own layout, which is why the example above is made of items.
Set dir="rtl" on the page or on any subtree — the collapsible adds no direction of its own, so
its contents decide. See the button page for a live example.
Accessibility
Section titled “Accessibility”- The summary is the button. It is focusable, announced as a disclosure, and toggles on Enter and Space with nothing added.
- Give it a real label. An icon-only trigger needs
.sr-onlytext, the same as any button. - Content inside stays searchable. Browsers open a closed
<details>to reveal a find-in-page match, which ahiddendiv would never do. - Do not nest interactive controls in the summary. A button inside a
<summary>is unreachable — the summary swallows the click. Put controls in the content instead.