Components
DisclosureGroup
Show or hide related content behind an expandable label.
Example
Requires React 18.2+ or 19 and shared styles. See setup.
Default
Loading preview…
Code
'use client';
import { VStack, Text } from '@swiftuijs/ui';
import { DisclosureGroup } from '@swiftuijs/ui';
export default function Example() {
return (<DisclosureGroup label="More Info">{(<VStack spacing={10} style={{ padding: '15px' }}>
<Text>Hidden content</Text>
<Text>This content is shown when expanded</Text>
</VStack>)}</DisclosureGroup>);
}SwiftUI Correspondence: Similar to SwiftUI's DisclosureGroup.
Web behavior: The toggle is linked to its content with stable IDs and aria-controls / aria-labelledby.
Usage and limitations
- Provide a descriptive
label. UsedefaultExpandedfor local state, orexpandedandonExpandedChangefor controlled state. - The trigger and content have linked ARIA attributes and keyboard activation.
- Closing unmounts children. Keep editable state above the group if it must survive closing.
More examples
Default Expanded
Controlled Mode
Multiple Groups
With Complex Content
API reference
| Prop | Type | Required | Description |
|---|---|---|---|
label | string | Yes | The label for the disclosure toggle. |
defaultExpanded | boolean | No | Whether the group is initially expanded. Default: false |
expanded | boolean | No | Controlled expanded state. If provided, the component becomes controlled. |
onExpandedChange | (expanded: boolean) => void | No | Callback fired when the expanded state changes. |
Inherits additional props from IBaseComponent.