Collapsible
An unstyled single-panel disclosure primitive with controlled/uncontrolled state, keyboard activation, and optional keepMounted retention.
Base Collapsible provides a single expandable disclosure panel. Root manages the open state, Trigger toggles it, and Content controls content visibility and mounting.
Preview
Section titled “Preview”The demo covers default unmounted content, initially open retained content, disabled-while-open content, and deferred controlled updates (activate the Trigger, then click Accept pending controlled request to commit the change).
Installation
Section titled “Installation”Available starting in 0.3.0-rc.1 and later releases. In the workspace, generate host components with the matching CLI:
proto-ui add react base-collapsible# Also supports vue, vue2, and wcReact, Vue, and Vue 2 generate BaseCollapsibleRoot, BaseCollapsibleTrigger, and BaseCollapsibleContent; Web Components register proto-ui-base-collapsible-{root,trigger,content}. You can also import collapsibleRoot, collapsibleTrigger, collapsibleContent, and asCollapsible* hooks directly from @proto.ui/prototypes-base/collapsible.
Anatomy
Section titled “Anatomy”Each Root contains one Trigger and one Content (nested Root instances stay isolated):
- Root: manages open state and exposes
openCollapsible,close,toggle, and theopenChangeevent. - Trigger: button semantics in natural Tab order with
Enter/Spaceactivation, derivedexpandedand effectivedisabledstates, andfocusSelf(). - Content: syncs
open/hiddenstate. Unmounts content when closed by default; setkeepMountedto keep the node mounted and hidden while preserving child state.
Code example
Section titled “Code example”import * as React from 'react';import { createReactAdapter } from '@proto.ui/adapter-react';import { collapsibleRoot, collapsibleTrigger, collapsibleContent,} from '@proto.ui/prototypes-base/collapsible';
const adapt = createReactAdapter(React);const BaseCollapsibleRoot = adapt(collapsibleRoot);const BaseCollapsibleTrigger = adapt(collapsibleTrigger);const BaseCollapsibleContent = adapt(collapsibleContent);
export function ControlledDisclosure() { const [open, setOpen] = React.useState(false); return ( <BaseCollapsibleRoot open={open} onOpenChange={(request) => setOpen(request.open)}> <BaseCollapsibleTrigger>Details</BaseCollapsibleTrigger> <BaseCollapsibleContent keepMounted>Additional details</BaseCollapsibleContent> </BaseCollapsibleRoot> );}
export function UncontrolledDisclosure() { return ( <BaseCollapsibleRoot defaultOpen> <BaseCollapsibleTrigger>Details</BaseCollapsibleTrigger> <BaseCollapsibleContent>Additional details</BaseCollapsibleContent> </BaseCollapsibleRoot> );}Controlled state and accessibility
Section titled “Controlled state and accessibility”- Pass
openfor controlled mode: requests emitopenChangewith{ open, reason }(reasonis'pointer','keyboard', or'programmatic'). Supply the newopenprop to commit the change. - Disabling either
RootorTriggerblocks activation; disabling an open panel keeps it open. Triggerautomatically managesaria-expandedandaria-controls, cleaning up ARIA links wheneverContentunmounts or is disposed.
Root Props
Section titled “Root Props”Passing open selects controlled mode.
| Prop | Type | Default |
|---|---|---|
open | boolean | — |
defaultOpen | boolean | false |
disabled | boolean | false |
Other parts
Section titled “Other parts”- Trigger:
disableddefaults tofalse. - Content:
keepMounteddefaults tofalse.