Collapsible
Alignment target:@astryxdesign/core v0.7.1 · Collapsible
Usage #
Collapsible folds one content region behind a trigger: the trigger stays visible and a click expands or collapses the content underneath. It belongs in settings panels, FAQ pages, and detail views — places where the page should stay easy to scan while still letting people drill into what they care about. Several collapsibles side by side form a plain accordion, each managing its own state.
The shortest form gives a label and the content:
<script setup lang="ts">
import { Collapsible } from '@astryx-vue/core/Collapsible'
</script>
<template>
<Collapsible trigger="Shipping address">
<p>Orders leave the warehouse within one business day, and the tracking number is emailed as soon as the parcel is scanned.</p>
</Collapsible>
</template>A collapsible starts expanded. Pass :default-is-open="false" when the content should stay hidden until someone asks for it. In that mode the component owns the state: clicking the trigger flips the content and reports the new state through the openChange event.
When something outside the component decides, lift the state with v-model:is-open. The component then renders exactly what the bound value says, and a click is only a request to change it:
<script setup lang="ts">
import { Collapsible } from '@astryx-vue/core/Collapsible'
import { ref } from 'vue'
const isOpen = ref(false)
</script>
<template>
<Collapsible v-model:is-open="isOpen" trigger="Release notes">
<p>Version 4.2 adds inline comments to shared reports.</p>
</Collapsible>
</template>The trigger is normally a plain text label passed to the trigger prop. When the label needs a heading, an icon, or extra controls, use the trigger slot instead; it replaces the prop completely. Expanding and collapsing play a real transition: the content region's height, padding, and opacity change together, and under prefers-reduced-motion: reduce the change lands immediately without the movement.
The trigger and the content are linked with aria-expanded and aria-controls, so a screen reader can move from the button straight to the region it controls. While collapsed the region stays the same element — aria-controls always points at it — but it is set to display: none, which keeps it out of the tab order and out of the accessibility tree.
chevronPosition decides which side of the label carries the disclosure chevron. The default end follows the label and points down while collapsed, up while expanded. Set it to start to lead the label with an arrow that points into the content while collapsed — mirrored in right-to-left layouts — and turns down when expanded, matching the rows of a file tree.
isDisabled dims the trigger, stops it responding to clicks, marks it aria-disabled, and takes it out of the tab order. It never collapses content that is already open; it only stops further changes.
Anatomy
| Element | Description |
|---|---|
| Container | The root that contains one trigger and its controlled content and, in a divided group, paints the item divider. |
| Trigger | The always-visible button that toggles the content. Shows a label and a chevron indicator. |
| Chevron | Animated disclosure arrow. It follows the label by default; chevronPosition="start" moves it ahead of the label, points inward when collapsed (mirrored under RTL), and turns down when expanded. |
| Content | The area that hides or reveals when the trigger is clicked. |
| Group container | The CollapsibleGroup wrapper rendered when dividers are enabled. It contains the coordinated items and carries their density. |
Best practices #
| Guidance | Practices |
|---|---|
| Do | Name what the section holds. The label is the button's accessible name, so a vague "More" or "Details" leaves screen reader users guessing. |
| Do | Collapse content that is long or only occasionally needed. A single short paragraph is better shown directly than hidden behind a click. |
| Do | Lift the state with v-model:isOpen when something outside the component decides, so the parent stays the single source of truth. |
| Do | Use chevronPosition="start" for nested rows and lists, where the arrow leaning into the content matches the file-tree convention, and keep the default end for standalone sections. |
| Do | Keep the trigger to its label. Put actions inside the content region or on their own row so a click is never ambiguous. |
| Don't | Hide critical or required content behind a collapsible. Many people will never open it, and the information is lost. |
| Don't | Nest collapsibles more than two levels deep; the content becomes hard to find and navigate. |
| Don't | Put the outcome of an action or an error inside a collapsible. Show that kind of message directly, or use a banner. |
Examples #
Collapsible — Controlled
Manage the open section from parent state, so something other than a click can move it: a URL parameter, a form jumping to the step that failed validation, or the Previous/Next controls shown here.
Collapsible — FAQ
FAQ built with hasDividers: row hairlines and density padding with no custom CSS. Questions use body semibold so a list of questions reads as rows rather than a stack of headings.
Collapsible — Multiple mode
Several sections open at once, for comparing across them. One Collapsible per Card, so each trigger keeps its own large type: it is the heading of its surface, not a row in a list.
Collapsible — Single mode
Only one section open at a time, so a single body of content competes for attention. Use defaultValue to pre-expand whichever section a first-time reader needs.
Collapsible — With dividers
main. 847 modules compiled with no warnings, and the bundle came in at 142 KB gzipped — 3 KB under the budget. Deployed by Sarah Chen · April 18, 3:42 PM · 2m 14s A flat list on the page background with hand-placed Dividers, for detail panels and sidebars where cards would add too much weight.