Collapsible
This is a headless disclosure component: a button that shows and hides one panel. You can control the open state, or you can let the component control it. The component also has a disabled state.
Anatomy
The collapsible has three parts. Collapsible.Root gives the shared context. Collapsible.Trigger makes the button. Collapsible.Panel contains the content that the trigger shows and hides.
<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 use open with onOpenChange, to control the panel from your own code. That control can be in a different part of the page. Use defaultOpen when the component controls its own state.
Usage guidelines
- Use
openandonOpenChangewhen your own code controls the state. UsedefaultOpenwhen the component controls the state. - Use
disabledto stop the trigger. - Use
forceMountonCollapsible.Panelwhen the content must stay in the DOM while the panel is closed. - For a set of sections where only one section opens at a time, use
Accordion.
Accessibility
Collapsible.Triggerhas button semantics witharia-expanded. Itsaria-controlsattribute points at the panel. This obeys the WAI-ARIA disclosure pattern.- While the panel is closed,
Collapsible.Panelishiddenandinert. The panel has theidthat the trigger points at. - The
Enterkey and theSpacekey open and close the panel, like a native button.
API reference
Root
The disclosure container. It holds the open state and gives the context to the trigger and to the panel.
* required. Native HTML attributes of the underlying element are also accepted.
Trigger
The button. It shows and hides the panel, with native button activation.
* required. Native HTML attributes of the underlying element are also accepted.
Panel
The content that the trigger shows and hides. While it is closed, it is hidden and inert.
* required. Native HTML attributes of the underlying element are also accepted.