Think of each component as a wheel in your app’s UI — smooth, connected, and full of potential. Build with harmony. Build with Chakra UI.
Usage
import { Collapsible } from "chakra-ui-solid";<Collapsible.Root>
<Collapsible.Trigger>
<Collapsible.Indicator />
</Collapsible.Trigger>
<Collapsible.Content />
</Collapsible.Root>Examples
Initial Open
Use the defaultOpen prop to render the collapsible in an open state by default.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Partial Height
Use the collapsedHeight prop to show a preview of the content when collapsed.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Disabled
Use the disabled prop to prevent the collapsible from being toggled.
disabled prop.Controlled
Use the open and onOpenChange props to control the collapsible state.
Store
An alternative way to control the collapsible is to use the RootProvider component and the
createCollapsible store hook.
createCollapsible hook and RootProvider allows you to access the collapsible store and control the state from anywhere in your component.Lazy Mounted
Use the unmountOnExit prop to make the content unmount when collapsed.
Guides
Accessing collapsible context
Use useCollapsibleContext to access the collapsible’s state and methods from any component inside
the collapsible.
import { Collapsible, useCollapsibleContext } from "chakra-ui-solid";
function CollapsibleStatus() {
const collapsible = useCollapsibleContext();
return <div>Collapsible is {collapsible.open ? "open" : "closed"}</div>;
}
function MyCollapsible() {
return (
<Collapsible.Root>
<Collapsible.Trigger>Toggle</Collapsible.Trigger>
<Collapsible.Content>
<CollapsibleStatus />
</Collapsible.Content>
</Collapsible.Root>
);
}Closing programmatically
Use setOpen(false) from the context to close the collapsible programmatically.
import { Button, Collapsible, useCollapsibleContext } from "chakra-ui-solid";
function CloseButton() {
const collapsible = useCollapsibleContext();
return <Button onClick={() => collapsible.setOpen(false)}>Close Collapsible</Button>;
}
function MyCollapsible() {
return (
<Collapsible.Root>
<Collapsible.Trigger>Toggle</Collapsible.Trigger>
<Collapsible.Content>
<CloseButton />
</Collapsible.Content>
</Collapsible.Root>
);
}Content Padding
To prevent janky animations when the collapsible expands or collapses, apply padding to the inner
content element rather than directly on Collapsible.Content to prevent visual stuttering as its
animations.
DO THIS:
<Collapsible.Root>
<Collapsible.Trigger>Toggle</Collapsible.Trigger>
<Collapsible.Content>
<Box padding="4" borderWidth="1px">
{/* Content here */}
</Box>
</Collapsible.Content>
</Collapsible.Root>NOT THIS:
<Collapsible.Root>
<Collapsible.Trigger>Toggle</Collapsible.Trigger>
{/* ❌ Avoid applying padding directly to Content */}
<Collapsible.Content padding="4" borderWidth="1px">
{/* Content here */}
</Collapsible.Content>
</Collapsible.Root>Props
Root
| Prop | Default | Type |
|---|---|---|
collapsedHeight | — | number | stringHow tall the content stays when closed, instead of collapsing away entirely — the "read more" shape. The content keeps its box and its tabbable children are made `inert`. |
collapsedWidth | — | number | stringThe horizontal counterpart of {@link CreateCollapsibleProps.collapsedHeight}. |
defaultOpen | — | booleanThe open state a fresh, uncontrolled collapsible starts in. |
disabled | — | booleanWhether the trigger ignores clicks. |
id | — | stringSeeds every id the machine hands out — the root is `collapsible:{id}`, the content `collapsible:{id}:content`, the trigger `collapsible:{id}:trigger`. Defaults to a generated id, and **does not become the root element's own `id`**: pass `ids` to control the attributes themselves. |
ids | — | CollapsibleElementIdsOverride individual element ids, for pointing an ARIA relationship at a specific one. |
lazyMount | false | booleanKeep the content out of the DOM entirely until the collapsible first opens. |
onExitComplete | — | VoidFunctionCalled once the exit animation has finished and the content is fully closed. |
onOpenChange | — | (details: CollapsibleOpenChangeDetails) => voidCalled whenever the open state changes, from either side. |
open | — | booleanThe controlled open state. Pass `undefined` for uncontrolled. |
unmountOnExit | false | booleanTake the content back out of the DOM once it has closed and its exit animation has finished, rather than leaving it there hidden. |
Plus Omit<HTMLChakraProps<"div">, "id"> — the whole style-prop surface and the DOM attributes of the element it renders, several hundred names listed as their sources rather than expanded — and the three every component takes: as, render and unstyled.
RootProvider
| Prop | Default | Type |
|---|---|---|
value* | — | CreateCollapsibleReturnA machine built by {@link createCollapsible}, so the consumer owns it rather than the Root. |
Plus HTMLChakraProps<"div"> — the whole style-prop surface and the DOM attributes of the element it renders, several hundred names listed as their sources rather than expanded — and the three every component takes: as, render and unstyled.
Context
| Prop | Default | Type |
|---|---|---|
children* | — | (collapsible: CreateCollapsibleReturn) => JSX.ElementReceives the machine, so a consumer can read its state without a component of their own. |
Plus the three every component takes: as, render and unstyled.
createCollapsible
| Prop | Default | Type |
|---|---|---|
collapsedHeight | — | number | stringHow tall the content stays when closed, instead of collapsing away entirely — the "read more" shape. The content keeps its box and its tabbable children are made `inert`. |
collapsedWidth | — | number | stringThe horizontal counterpart of {@link CreateCollapsibleProps.collapsedHeight}. |
defaultOpen | — | booleanThe open state a fresh, uncontrolled collapsible starts in. |
disabled | — | booleanWhether the trigger ignores clicks. |
id | — | stringSeeds every id the machine hands out — the root is `collapsible:{id}`, the content `collapsible:{id}:content`, the trigger `collapsible:{id}:trigger`. Defaults to a generated id, and **does not become the root element's own `id`**: pass `ids` to control the attributes themselves. |
ids | — | CollapsibleElementIdsOverride individual element ids, for pointing an ARIA relationship at a specific one. |
lazyMount | false | booleanKeep the content out of the DOM entirely until the collapsible first opens. |
onExitComplete | — | VoidFunctionCalled once the exit animation has finished and the content is fully closed. |
onOpenChange | — | (details: CollapsibleOpenChangeDetails) => voidCalled whenever the open state changes, from either side. |
open | — | booleanThe controlled open state. Pass `undefined` for uncontrolled. |
unmountOnExit | false | booleanTake the content back out of the DOM once it has closed and its exit animation has finished, rather than leaving it there hidden. |
Plus the three every component takes: as, render and unstyled.