Collapsible
Conceals or reveals content sections, enhancing space utilization and organization.
@huntabyte starred 3 repositories
Structure
Controlled Usage
Sometimes, you want to either control or be aware of the open
state of the collapsible from outside of the component. To do so, you can bind to the open
prop.
Svelte Transitions
You can use the forceMount
prop on the Collapsible.Content
component to forcefully mount the content regardless of whether the collapsible is opened or not. This is useful when you want more control over the transitions when the collapsible opens and closes using something like Svelte Transitions.
The open
snippet prop can be used for conditional rendering of the content based on whether the collapsible is open.
With the amount of boilerplate needed to handle the transitions, it's recommended to componentize your custom implementation of the collapsible content and use that throughout your application.
API Reference
The root collapsible container which manages the state of the collapsible.
Property | Type | Description |
---|---|---|
open bindable prop | boolean | The open state of the collapsible. The content will be visible when this is true, and hidden when it's false. Default: false |
disabled | boolean | Whether or not the collapsible is disabled. This prevents the user from interacting with it. Default: false |
onOpenChange | function | A callback that is fired when the collapsible's open state changes. Default: undefined |
ref bindable prop | HTMLDivElement | The underlying DOM element being rendered. You can bind to this to get a reference to the element. Default: undefined |
children | Snippet | The children content to render. Default: undefined |
child | Snippet | Use render delegation to render your own element. See delegation docs for more information. Default: undefined |
Data Attribute | Value | Description |
---|---|---|
data-state | enum | The collapsible's open state. |
data-disabled | '' | Present when the collapsible is disabled. |
data-collapsible-root | '' | Present on the root element. |
The button responsible for toggling the collapsible's open state.
Property | Type | Description |
---|---|---|
ref bindable prop | HTMLButtonElement | The underlying DOM element being rendered. You can bind to this to get a reference to the element. Default: undefined |
children | Snippet | The children content to render. Default: undefined |
child | Snippet | Use render delegation to render your own element. See delegation docs for more information. Default: undefined |
Data Attribute | Value | Description |
---|---|---|
data-state | enum | The collapsible's open state. |
data-disabled | '' | Present when the collapsible or this trigger is disabled. |
data-collapsible-trigger | '' | Present on the trigger element. |
The content displayed when the collapsible is open.
Property | Type | Description |
---|---|---|
forceMount | boolean | Whether or not to forcefully mount the content. This is useful if you want to use Svelte transitions or another animation library for the content. Default: false |
ref bindable prop | HTMLDivElement | The underlying DOM element being rendered. You can bind to this to get a reference to the element. Default: undefined |
children | Snippet | The children content to render. Default: undefined |
child | Snippet | Use render delegation to render your own element. See delegation docs for more information. Default: undefined |
Data Attribute | Value | Description |
---|---|---|
data-state | enum | The collapsible's open state. |
data-disabled | '' | Present when the collapsible is disabled. |
data-collapsible-content | '' | Present on the content element. |
CSS Variable | Description |
---|---|
--bits-collapsible-content-height | The height of the collapsible content element. |
--bits-collapsible-content-width | The width of the collapsible content element. |