Data display
Collapsible
Free14.3 KB gzippedA show/hide section (WAI-ARIA disclosure). See CollapsibleRoot.
Accessibility: WCAG 2.2 AA · No A or AA violations in light or dark mode · Keys: Tab, Enter, Space · Full report
Import
import { Collapsible } from "@vjdesigns/vjdesigns-ui";
Importing only Collapsible adds about 14.3 KB of minified, gzipped JavaScript to your app (React not included). The stylesheet is shared by every component and loaded once: 75.1 KB gzipped.
Examples
Basic
One section that shows and hides. The trigger is a real button with aria-expanded and aria-controls, and the chevron turns when it opens.
import { Collapsible, Text } from "@vjdesigns/vjdesigns-ui";
export function Basic() {
return (
<div style={{ width: "100%", maxWidth: "30rem" }}>
<Collapsible>
<Collapsible.Trigger>Shipping details</Collapsible.Trigger>
<Collapsible.Content>
<Text tone="muted" style={{ paddingBlock: "0.5rem" }}>
Orders ship within one business day and arrive in 3 to 5 days. Tracking is emailed when your order leaves the warehouse.
</Text>
</Collapsible.Content>
</Collapsible>
</div>
);
}
Show more
The trigger and content can sit anywhere inside the root, such as a "Show more" button below a list. Here open and onOpenChange control it, so the button's label can change; defaultOpen starts an uncontrolled one open.
- Ava Thompson, point guard
- Marcus Lee, shooting guard
- Jordan Diaz, small forward
import { useState } from "react";
import { Collapsible, List } from "@vjdesigns/vjdesigns-ui";
export function ShowMore() {
const [open, setOpen] = useState(false);
return (
<div style={{ width: "100%", maxWidth: "30rem" }}>
<Collapsible open={open} onOpenChange={setOpen}>
<List>
<List.Item>Ava Thompson, point guard</List.Item>
<List.Item>Marcus Lee, shooting guard</List.Item>
<List.Item>Jordan Diaz, small forward</List.Item>
</List>
<Collapsible.Content>
<List>
<List.Item>Sam Okafor, power forward</List.Item>
<List.Item>Riley Chen, center</List.Item>
</List>
</Collapsible.Content>
<Collapsible.Trigger size="sm">{open ? "Show fewer players" : "Show 2 more players"}</Collapsible.Trigger>
</Collapsible>
</div>
);
}
Custom trigger
asChild passes the trigger's ARIA attributes and click handler to your own button. indicator={false} hides the chevron, and disabled keeps the section as it is.
import {
Button,
Collapsible,
Stack,
Switch,
Text,
} from "@vjdesigns/vjdesigns-ui";
export function CustomTrigger() {
return (
<Stack gap={4} style={{ width: "100%", maxWidth: "30rem" }}>
<Collapsible>
<Collapsible.Trigger asChild>
<Button variant="outline" size="sm">
Advanced settings
</Button>
</Collapsible.Trigger>
<Collapsible.Content>
<Stack gap={3} style={{ paddingBlock: "0.75rem" }}>
<Switch label="Send usage reports" />
<Switch label="Enable beta features" />
</Stack>
</Collapsible.Content>
</Collapsible>
<Collapsible disabled>
<Collapsible.Trigger indicator={false}>Billing (owners only)</Collapsible.Trigger>
<Collapsible.Content>
<Text tone="muted">Only workspace owners can change billing.</Text>
</Collapsible.Content>
</Collapsible>
</Stack>
);
}
Accessibility
Closed content is hidden, so it can't be focused or read. With hiddenUntilFound, the browser's find-in-page (Ctrl+F) can still search it and opens the section on a match. The height animates, and the change is instant with reduced motion.
You can ask for a full refund within 14 days of buying. Try searching this page for "refund window".
import { Collapsible, Text } from "@vjdesigns/vjdesigns-ui";
export function Accessibility() {
return (
<div style={{ width: "100%", maxWidth: "30rem" }}>
<Collapsible>
<Collapsible.Trigger>Refund policy</Collapsible.Trigger>
<Collapsible.Content hiddenUntilFound>
<Text tone="muted" style={{ paddingBlock: "0.5rem" }}>
You can ask for a full refund within 14 days of buying. Try searching this page for "refund window".
</Text>
</Collapsible.Content>
</Collapsible>
</div>
);
}
Right to left
The first example again, inside a right-to-left LocaleProvider (Arabic). Layout, spacing and arrow icons mirror, and the components' built-in text is translated. The example's own text stays in English.
Basic
import { LocaleProvider } from "@vjdesigns/vjdesigns-ui";
import ar from "@vjdesigns/vjdesigns-ui/locales/ar";
// Basic is the "Basic" example above.
<LocaleProvider locale="ar" messages={ar}>
<Basic />
</LocaleProvider>
API reference
Collapsible
New in 3.5.1| Prop | Type | Default |
|---|---|---|
openControlled open state. | boolean | — |
defaultOpenInitial open state when uncontrolled. | boolean | false |
onOpenChangeCalled with the next open state when the trigger is pressed (or find-in-page reveals the content). | (open: boolean) => void | — |
disabledDisables the trigger, so the section stays in its current state. | boolean | false |
childrenA | ReactNode | — |
Also accepts native <div> attributes, plus className, style and ref.
Collapsible.Trigger
New in 3.5.1The button that opens and closes the content. Renders a Button (variant="ghost", tone="neutral" by default) with a turning chevron, or your own element with asChild.
| Prop | Type | Default |
|---|---|---|
asChildRender your own element instead of a | boolean | false |
indicatorShow a chevron after the label that turns when open. Ignored with | boolean | true |
childrenThe visible label, or your element with | ReactNode | — |
variantVisual style. Inherits from a surrounding | "solid""soft""outline""ghost""link""inverse" | "solid" |
toneSemantic color. Inherits from a surrounding | "neutral""primary""accent""success""warning""danger""info" | "primary" |
sizeControl height, padding, and type size. Inherits from a surrounding | "sm""md""lg" | "md" |
radiusCorner rounding. When omitted, uses | "none""xs""sm""md""lg""xl""2xl""pill" | "pill" |
disabledDisables the control. Buttons use the native | boolean | false |
Also accepts native <button> attributes, plus className, style and ref.
Collapsible.Content
New in 3.5.1The content the trigger controls. Animates its height open and closed (instantly under prefers-reduced-motion), then gets the hidden attribute. Adds no padding, so it fits any layout.
| Prop | Type | Default |
|---|---|---|
forceMountKeep the children mounted while closed (still hidden), e.g. to keep form state. | boolean | false |
hiddenUntilFoundUse | boolean | false |
childrenThe content to show and hide. | ReactNode | — |
Also accepts native <div> attributes, plus className, style and ref.
See what changed in each version in the Changelog.
Accessibility report
Collapsible targets WCAG 2.2 AA. Below: a live axe-core audit of this page's examples, Lighthouse scores for the page in both modes, the accessibility behavior built into the component, and the checks only a person can do.
axe-core audit (live)
Checking the examples above…
Lighthouse audit
Light mode
Score 10035 passed · 0 failed · 30 not applicable · 10 to check by hand
Dark mode
Score 10035 passed · 0 failed · 30 not applicable · 10 to check by hand
Lighthouse 13.5.0 audits the whole docs page (header and sidebar included), not just the examples, in English. Last run 11/27/2026. Some failed audits carry no weight in the score, so a page can score 100 and still list one.
Built-in behavior
Keyboard
| Key | Action |
|---|---|
| Tab | Moves to the trigger, then into the content when it's open. |
| EnterSpace | Opens or closes the content. |
Roles and states
| Element | Role | States and properties |
|---|---|---|
Trigger <button> | button | aria-expanded, aria-controls → content, disabled |
| Content | none (generic) | hidden while closed (hidden="until-found" with hiddenUntilFound) |
Manual checks
Automated tools find roughly a third of accessibility issues. Test these in your app, with your content.
| Check | What to test | WCAG 2.2 |
|---|---|---|
| Keyboard | Every action works with Tab, Shift+Tab, Enter, Space and the arrow keys, and focus never gets stuck. | 2.1.1 (A), 2.1.2 (A) |
| Focus | Focus moves in a logical order, is always visible, and isn't hidden behind sticky headers. | 2.4.3 (A), 2.4.7 (AA), 2.4.11 (AA), 2.4.13 (AAA) |
| Screen readers | Names, roles and states are announced correctly, and status changes are announced without moving focus. | 1.3.1 (A), 4.1.2 (A), 4.1.3 (AA) |
| Color | Meaning never depends on color alone; your own colors meet contrast in both modes. | 1.4.1 (A), 1.4.3 (AA), 1.4.11 (AA), 1.4.6 (AAA) |
| Zoom and reflow | At 200% text size and at 320px wide (400% zoom), nothing is cut off and no sideways scrolling is needed. | 1.4.4 (AA), 1.4.10 (AA), 1.4.12 (AA) |
| Pointer targets | Click and tap targets are at least 24×24px (44×44px for AAA), or spaced so they don't overlap. | 2.5.8 (AA), 2.5.5 (AAA) |
| Motion | Animations respect the reduced-motion setting. | 2.3.3 (AAA) |