A disclosure is a collapsible section of content. It is composed of a a header with a heading and trigger button, and a panel that contains the content.
Vanilla CSS theme
--tint CSS variable used by the Vanilla CSS examples.Expanding
Use the isExpanded or defaultExpanded prop to set the expanded state, and onExpandedChange to handle user interactions.
import {Disclosure, DisclosureHeader, DisclosurePanel} from './Disclosure';
import {useState} from 'react';
function Example() {
let [isExpanded, setIsExpanded] = useState(true);
return (
<Disclosure
isExpanded={isExpanded}
onExpandedChange={setIsExpanded}>
<DisclosureHeader>Download, Install, and Set Up</DisclosureHeader>
<DisclosurePanel>Instructions on how to download, install, and set up</DisclosurePanel>
</Disclosure>
);
}
Content
Add interactive elements such as buttons adjacent to the disclosure heading by wrapping them in a <div>. <Heading> and <Button> must not have interactive children.
import {Disclosure, DisclosureHeader, DisclosurePanel} from './Disclosure';
import {Button} from './Button';
import {Settings} from 'lucide-react';
<Disclosure style={{width: 200}}>
<div style={{display: 'flex', alignItems: 'center', gap: 8}}>
<DisclosureHeader style={{flex: 1}}>Files</DisclosureHeader>
<Button aria-label="Settings"><Settings /></Button>
</div>
<DisclosurePanel>Files content</DisclosurePanel>
</Disclosure>
API
<Disclosure>
<Heading>
<Button slot="trigger" />
</Heading>
<DisclosurePanel />
</Disclosure>
Disclosure
A disclosure is a collapsible section of content. It is composed of a a header with a heading and trigger button, and a panel that contains the content.
| Name | Type | |
|---|---|---|
id | Key | |
An id for the disclosure when used within a DisclosureGroup, matching the id used in | ||
isDisabled | boolean | |
Whether the disclosure is disabled. | ||
isExpanded | boolean | |
Whether the disclosure is expanded (controlled). | ||
defaultExpanded | boolean | |
Whether the disclosure is expanded by default (uncontrolled). | ||
children | ChildrenOrFunction | |
The children of the component. A function may be provided to alter the children based on component state. | ||
Default className: react-aria-Disclosure
| Render Prop | CSS Selector |
|---|---|
isExpanded | CSS Selector: [data-expanded]
|
| Whether the disclosure is expanded. | |
isFocusVisibleWithin | CSS Selector: [data-focus-visible-within]
|
| Whether the disclosure has keyboard focus. | |
isDisabled | CSS Selector: [data-disabled]
|
| Whether the disclosure is disabled. | |
state | CSS Selector: — |
| State of the disclosure. | |
DisclosurePanel
A DisclosurePanel provides the content for a disclosure.
| Name | Type | Default |
|---|---|---|
children | ReactNode | Default: — |
The children of the component. | ||
labelElementType | ElementType | Default: 'label'
|
The HTML element used to render the label, e.g. 'label', or 'span'. | ||
Default className: react-aria-DisclosurePanel
| Render Prop | CSS Selector |
|---|---|
isFocusVisibleWithin | CSS Selector: [data-focus-visible-within]
|
| Whether keyboard focus is within the disclosure panel. | |
| CSS Variable |
|---|
--disclosure-panel-width |
| The disclosure panel's intrinsic width in pixels. Useful for animations. |
--disclosure-panel-height |
| The disclosure panel's intrinsic height in pixels. Useful for animations. |