Skip to content
Vertical Jump Designs-uiFront-End Studio
Get Pro

v3.9 is out.

Data display

Collapsible

Free14.3 KB gzipped

A 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

tsx
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.

tsx
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
tsx
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.

tsx
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.

tsx
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

tsx
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
Collapsible props
PropTypeDefault
open

Controlled open state.

boolean—
defaultOpen

Initial open state when uncontrolled.

booleanfalse
onOpenChange

Called with the next open state when the trigger is pressed (or find-in-page reveals the content).

(open: boolean) => void—
disabled

Disables the trigger, so the section stays in its current state.

booleanfalse
children

A Collapsible.Trigger and a Collapsible.Content, anywhere inside.

ReactNode—

Also accepts native <div> attributes, plus className, style and ref.

Collapsible.Trigger

New in 3.5.1

The 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.

Collapsible.Trigger props
PropTypeDefault
asChild

Render your own element instead of a Button, passing it the trigger's ARIA attributes, onClick, and ref. It must be a single element that renders a <button> (or a component that forwards these props to one).

booleanfalse
indicator

Show a chevron after the label that turns when open. Ignored with asChild.

booleantrue
children

The visible label, or your element with asChild.

ReactNode—
variant

Visual style. Inherits from a surrounding ButtonGroup.

"solid""soft""outline""ghost""link""inverse""solid"
tone

Semantic color. Inherits from a surrounding ButtonGroup.

"neutral""primary""accent""success""warning""danger""info""primary"
size

Control height, padding, and type size. Inherits from a surrounding ButtonGroup.

"sm""md""lg""md"
radius

Corner rounding. When omitted, uses --control-radius (pill).

"none""xs""sm""md""lg""xl""2xl""pill""pill"
disabled

Disables the control. Buttons use the native disabled attribute; links drop href and get aria-disabled.

booleanfalse

Also accepts native <button> attributes, plus className, style and ref.

Collapsible.Content

New in 3.5.1

The 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.

Collapsible.Content props
PropTypeDefault
forceMount

Keep the children mounted while closed (still hidden), e.g. to keep form state.

booleanfalse
hiddenUntilFound

Use hidden="until-found" where supported, so the browser's find-in-page can search the closed content and opens it on a match. Keeps the children mounted.

booleanfalse
children

The 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)

Running accessibility audit

Checking the examples above…

Lighthouse audit

Light mode

Score 100

35 passed · 0 failed · 30 not applicable · 10 to check by hand

Dark mode

Score 100

35 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

Keyboard
KeyAction
TabMoves to the trigger, then into the content when it's open.
EnterSpaceOpens or closes the content.

Roles and states

Roles and states
ElementRoleStates and properties
Trigger <button>buttonaria-expanded, aria-controls → content, disabled
Contentnone (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.

Manual accessibility checks
CheckWhat to testWCAG 2.2
KeyboardEvery 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)
FocusFocus 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 readersNames, 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)
ColorMeaning 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 reflowAt 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 targetsClick 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)
MotionAnimations respect the reduced-motion setting.2.3.3 (AAA)