Collapsible
A headless single disclosure primitive: a button that shows and hides an associated panel, with controlled or uncontrolled open state and a disabled state.
Anatomy
The collapsible is assembled from three parts. Collapsible.Root provides the shared context, Collapsible.Trigger renders the toggle button, and Collapsible.Panel holds the content that is shown and hidden.
<script>
import { Collapsible } from '@human-kit/ui';
</script>
<Collapsible.Root defaultOpen>
<Collapsible.Trigger>Details</Collapsible.Trigger>
<Collapsible.Panel>Hidden content revealed on toggle.</Collapsible.Panel>
</Collapsible.Root>Controlled state
Bind open (or pair open with onOpenChange) to drive the panel from outside — for example from buttons elsewhere in the UI. Use defaultOpen instead when the collapsible should manage its own state.
Usage guidelines
- Use
open/onOpenChangefor controlled state anddefaultOpenfor uncontrolled state. - Use
disabledto prevent the trigger from toggling the panel. - Use
forceMountonCollapsible.Panelwhen collapsed content must stay in the DOM. - For grouped disclosures where only one section opens at a time, use
Accordioninstead.
Accessibility
Collapsible.Triggerrenders button semantics witharia-expandedandaria-controlspointing at the panel, following the WAI-ARIA disclosure pattern.Collapsible.Panelishidden+inertwhile collapsed and carries theidreferenced by the trigger.- Enter/Space toggle the panel via native button activation.
API reference
Root
The disclosure container. Holds the open state and provides context to the trigger and panel.
* required. Native HTML attributes of the underlying element are also accepted.
Trigger
The toggle button. Shows and hides the panel via native button activation.
* required. Native HTML attributes of the underlying element are also accepted.
Panel
The content shown and hidden by the trigger. Hidden and inert while collapsed.
* required. Native HTML attributes of the underlying element are also accepted.