bits

Collapsible

An interactive component which expands and collapses content.

@huntabyte starred 3 repositories

@huntabyte/bits

Structure

	<script lang="ts">
  import { Collapsible } from "bits-ui";
</script>
 
<Collapsible.Root>
  <Collapsible.Trigger />
  <Collapsible.Content />
</Collapsible.Root>
	<script lang="ts">
  import { Collapsible } from "bits-ui";
</script>
 
<Collapsible.Root>
  <Collapsible.Trigger />
  <Collapsible.Content />
</Collapsible.Root>

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.

	<script lang="ts">
  import { Collapsible } from "bits-ui";
  let collapsibleOpen = false;
</script>
 
<button on:click={() => (collapsibleOpen = true)}>Open</button>
<Collapsible.Root bind:open={collapsibleOpen}>
  <Collapsible.Trigger />
  <Collapsible.Content />
</Collapsible.Root>
	<script lang="ts">
  import { Collapsible } from "bits-ui";
  let collapsibleOpen = false;
</script>
 
<button on:click={() => (collapsibleOpen = true)}>Open</button>
<Collapsible.Root bind:open={collapsibleOpen}>
  <Collapsible.Trigger />
  <Collapsible.Content />
</Collapsible.Root>

Component API

Collapsible.Root

The root collapsible container which manages the state of the collapsible.

Property Type Description
disabled
boolean

Whether or not the collapsible is disabled. This prevents the user from interacting with it.

Default: false
open
boolean

The open state of the collapsible. The content will be visible when this is true, and hidden when it's false.

Default: false
onOpenChange
(open: boolean) => void

A callback that is fired when the collapsible's open state changes.

Default:  —— undefined
Data Attribute Description/Value
data-disabled

Present when the checkbox is disabled.

Value: ''
data-state

The collapsible's open state.

Value: 'open' | 'closed'

Collapsible.Trigger

The button responsible for toggling the collapsible's open state.

Property Type Description
asChild
boolean

Whether to use render delegation with this component or not.

Default: false
Data Attribute Description/Value
data-disabled

Present when the checkbox is disabled.

Value: ''
data-state

The collapsible's open state.

Value: 'open' | 'closed'

Collapsible.Content

The content displayed when the collapsible is open.

Property Type Description
asChild
boolean

Whether to use render delegation with this component or not.

Default: false
Data Attribute Description/Value
data-disabled

Present when the checkbox is disabled.

Value: ''
data-state

The collapsible's open state.

Value: 'open' | 'closed'

🚧 UNDER CONSTRUCTION 🚧