Collapsible
A collapsible panel controlled by a button.
View as MarkdownAnatomy
Import the component and assemble its parts:
import { Collapsible } from '@base-ui/react/collapsible';
<Collapsible.Root>
<Collapsible.Trigger />
<Collapsible.Panel />
</Collapsible.Root>API reference
Root
Groups all parts of the collapsible.
Renders a <div> element.
defaultOpenbooleanfalse
boolean- Name
- Description
Whether the collapsible panel is initially open.
To render a controlled collapsible, use the
openprop instead.- Type
boolean | undefined- Default
false
openboolean—
boolean- Name
- Description
Whether the collapsible panel is currently open.
To render an uncontrolled collapsible, use the
defaultOpenprop instead.- Type
boolean | undefined
onOpenChangefunction—
function- Name
- Description
Event handler called when the panel is opened or closed.
- Type
| (( open: boolean, eventDetails: Collapsible.Root.ChangeEventDetails, ) => void) | undefined
disabledbooleanfalse
boolean- Name
- Description
Whether the component should ignore user interaction.
- Type
boolean | undefined- Default
false
classNamestring | function—
string | function- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | ((state: Collapsible.Root.State) => string | undefined) | undefined
styleReact.CSSProperties | function—
React.CSSProperties | function- Name
- Type
| React.CSSProperties | (( state: Collapsible.Root.State, ) => React.CSSProperties | undefined) | undefined
renderReactElement | function—
ReactElement | function- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: Collapsible.Root.State, ) => ReactElement) | undefined
Additional Types
Collapsible.Root.Props
Re-Export of Root props as CollapsibleRootProps
Collapsible.Root.State
type CollapsibleRootState = { open: boolean; disabled: boolean };Collapsible.Root.ChangeEventReason
type CollapsibleRootChangeEventReason = 'trigger-press' | 'none';Collapsible.Root.ChangeEventDetails
type CollapsibleRootChangeEventDetails =
| {
reason: 'trigger-press';
event: MouseEvent | PointerEvent | TouchEvent | KeyboardEvent;
cancel: () => void;
allowPropagation: () => void;
isCanceled: boolean;
isPropagationAllowed: boolean;
trigger: Element | undefined;
}
| {
reason: 'none';
event: Event;
cancel: () => void;
allowPropagation: () => void;
isCanceled: boolean;
isPropagationAllowed: boolean;
trigger: Element | undefined;
};Trigger
A button that opens and closes the collapsible panel.
Renders a <button> element.
nativeButtonbooleantrue
boolean- Name
- Description
Whether the component renders a native
<button>element when replacing it via therenderprop. Set tofalseif the rendered element is not a button (for example,<div>).- Type
boolean | undefined- Default
true
classNamestring | function—
string | function- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | ((state: Collapsible.Root.State) => string | undefined) | undefined
styleReact.CSSProperties | function—
React.CSSProperties | function- Name
- Type
| React.CSSProperties | (( state: Collapsible.Root.State, ) => React.CSSProperties | undefined) | undefined
renderReactElement | function—
ReactElement | function- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: Collapsible.Root.State, ) => ReactElement) | undefined
data-panel-open
Additional Types
Collapsible.Trigger.Props
Re-Export of Trigger props as CollapsibleTriggerProps
Panel
A panel with the collapsible contents.
Renders a <div> element.
- Name
- Description
Allows the browser’s built-in page search to find and expand the panel contents.
Overrides the
keepMountedprop and useshidden="until-found"to hide the element without removing it from the DOM.- Type
boolean | undefined- Default
false
classNamestring | function—
string | function- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | ((state: Collapsible.Panel.State) => string | undefined) | undefined
styleReact.CSSProperties | function—
React.CSSProperties | function- Name
- Type
| React.CSSProperties | (( state: Collapsible.Panel.State, ) => React.CSSProperties | undefined) | undefined
keepMountedbooleanfalse
boolean- Name
- Description
Whether to keep the element in the DOM while the panel is hidden. This prop is ignored when
hiddenUntilFoundis used.- Type
boolean | undefined- Default
false
renderReactElement | function—
ReactElement | function- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: Collapsible.Panel.State, ) => ReactElement) | undefined
data-open
data-closed
data-starting-style
data-ending-style
--collapsible-panel-height
The collapsible panel’s height.
--collapsible-panel-width
The collapsible panel’s width.
Additional Types
Collapsible.Panel.Props
Re-Export of Panel props as CollapsiblePanelProps
Collapsible.Panel.State
type CollapsiblePanelState = {
transitionStatus: TransitionStatus;
open: boolean;
disabled: boolean;
};