Disclosure
A headless, accessible disclosure (collapsible) primitive for toggling content visibility.
Features
- Toggle visibility
- Controlled or uncontrolled open state
- Semantic trigger button
- ARIA-expanded and ARIA-controls wiring
- Unmounts when closed
- Headless styling
Installation
npm install @ariaui/disclosure
Examples
Two layouts from the legacy doc: a narrow collapsible list (Heroicons trigger) and a wider playground row (Lucide chevrons). Both use the same Root / Trigger / Content model; style open and closed states with data-[state=open]: utilities.
Collapsible
A compact disclosure: trigger beside a title, with stacked rows inside the panel.
No preview output yet.
Framer Motion
The compact collapsible disclosure animated with Framer Motion through Content asChild composition.
No preview output yet.
Anatomy
import * as Disclosure from "@ariaui/disclosure";
export default function Example() {
return (
<Disclosure.Root>
<Disclosure.Trigger />
<Disclosure.Content />
</Disclosure.Root>
);
}
API Reference
Root
State container. Owns the open/closed state and provides context to Trigger and Content.
| Prop | Type | Default |
|---|---|---|
open | boolean | — |
defaultOpen | boolean | false |
onOpenChange | (open: boolean) => void | — |
Trigger
Button that toggles the disclosure open/closed. Renders as a native button element.
| Attribute | Values |
|---|---|
| aria-expanded | "true" when open, "false" when closed |
| aria-controls | ID of the Content element |
| type | button |
Content
Container for the collapsible content. Only rendered in the DOM when the disclosure is open.
| Prop | Type | Default |
|---|---|---|
asChild | boolean | false |
Keyboard
| Shortcut | Action |
|---|---|
| Enter | Toggle the disclosure open/closed when the trigger is focused. |
| Space | Toggle the disclosure open/closed when the trigger is focused. |
| Tab | Move focus to the next focusable element. |
| Shift+Tab | Move focus to the previous focusable element. |
Accessibility
The Disclosure component implements the WAI-ARIA Disclosure pattern:
Triggerrenders as a native<button>element withtype="button".Triggercarriesaria-expandedreflecting the current open/closed state.Triggercarriesaria-controlspointing to theContentelement's ID.Contentis removed from the DOM when closed, making it inaccessible to assistive technologies.- Click, Enter, and Space on the trigger all toggle the disclosure state.