Skip to content
UI

Collapsible

An interactive component which expands and collapses a content area.

<script setup lang="ts">
import { Collapsible } from '@destyler-ui/vue'
</script>

<template>
  <Collapsible.Root>
    <Collapsible.Trigger>Toggle</Collapsible.Trigger>
    <Collapsible.Content>Content</Collapsible.Content>
  </Collapsible.Root>
</template>
import { Collapsible } from '@destyler-ui/react'

export function Basic(props: Collapsible.RootProps) {
  return (
    <Collapsible.Root {...props}>
      <Collapsible.Trigger>Toggle</Collapsible.Trigger>
      <Collapsible.Content>Content</Collapsible.Content>
    </Collapsible.Root>
  )
}
import { Collapsible } from '@destyler-ui/solid/collapsible'

export function Basic() {
  return (
    <Collapsible.Root>
      <Collapsible.Trigger>Toggle</Collapsible.Trigger>
      <Collapsible.Content>Content</Collapsible.Content>
    </Collapsible.Root>
  )
}
<script lang="ts">
  import type { CollapsibleRootProps } from '@destyler-ui/svelte'
  import { Collapsible } from '@destyler-ui/svelte'
  const props: CollapsibleRootProps = $props()
</script>
<Collapsible.Root {...props}>
  <Collapsible.Trigger>Toggle</Collapsible.Trigger>
  <Collapsible.Content>Content</Collapsible.Content>
</Collapsible.Root>
<script setup lang="ts">
import { Collapsible } from '@destyler-ui/vue'
</script>
<template>
<Collapsible.Root>
<Collapsible.Trigger />
<Collapsible.Content />
</Collapsible.Root>
</template>
import { Collapsible } from '@destyler-ui/react'
export default function Basic() {
return (
<Collapsible.Root>
<Collapsible.Trigger />
<Collapsible.Content />
</Collapsible.Root>
)
}
import { Collapsible } from '@destyler-ui/solid'
export default function Basic() {
return (
<Collapsible.Root>
<Collapsible.Trigger />
<Collapsible.Content />
</Collapsible.Root>
)
}
<script lang="ts">
import { Collapsible } from '@destyler-ui/svelte'
</script>
<Collapsible.Root>
<Collapsible.Trigger>Toggle</Collapsible.Trigger>
<Collapsible.Content>Content</Collapsible.Content>
</Collapsible.Root>
<script setup lang="ts">
import { Collapsible } from '@destyler-ui/vue'
</script>

<template>
  <Collapsible.Root>
    <Collapsible.Trigger>Toggle</Collapsible.Trigger>
    <Collapsible.Content>Content</Collapsible.Content>
  </Collapsible.Root>
</template>
import { Collapsible } from '@destyler-ui/react'

export function Basic(props: Collapsible.RootProps) {
  return (
    <Collapsible.Root {...props}>
      <Collapsible.Trigger>Toggle</Collapsible.Trigger>
      <Collapsible.Content>Content</Collapsible.Content>
    </Collapsible.Root>
  )
}
import { Collapsible } from '@destyler-ui/solid/collapsible'

export function Basic() {
  return (
    <Collapsible.Root>
      <Collapsible.Trigger>Toggle</Collapsible.Trigger>
      <Collapsible.Content>Content</Collapsible.Content>
    </Collapsible.Root>
  )
}
<script lang="ts">
  import type { CollapsibleRootProps } from '@destyler-ui/svelte'
  import { Collapsible } from '@destyler-ui/svelte'
  const props: CollapsibleRootProps = $props()
</script>
<Collapsible.Root {...props}>
  <Collapsible.Trigger>Toggle</Collapsible.Trigger>
  <Collapsible.Content>Content</Collapsible.Content>
</Collapsible.Root>

Open the collapsible by default.

<script setup lang="ts">
import { Collapsible } from '@destyler-ui/vue'
</script>

<template>
  <Collapsible.Root defaultOpen>
    <Collapsible.Trigger>Toggle</Collapsible.Trigger>
    <Collapsible.Content>Content</Collapsible.Content>
  </Collapsible.Root>
</template>
import { Collapsible } from '@destyler-ui/react'

export function InitialOpen() {
  return (
    <Collapsible.Root defaultOpen>
      <Collapsible.Trigger>Toggle</Collapsible.Trigger>
      <Collapsible.Content>Content</Collapsible.Content>
    </Collapsible.Root>
  )
}
import { Collapsible } from '@destyler-ui/solid/collapsible'

export function InitialOpen() {
  return (
    <Collapsible.Root open>
      <Collapsible.Trigger>Toggle</Collapsible.Trigger>
      <Collapsible.Content>Content</Collapsible.Content>
    </Collapsible.Root>
  )
}
<script lang="ts">import { Collapsible } from '@destyler-ui/svelte'</script>
<Collapsible.Root defaultOpen><Collapsible.Trigger>Toggle</Collapsible.Trigger><Collapsible.Content>Content</Collapsible.Content></Collapsible.Root>

Mount the content lazily when first opened.

<script setup lang="ts">
import { Collapsible } from '@destyler-ui/vue'
</script>

<template>
  <Collapsible.Root lazyMount>
    <Collapsible.Trigger>Toggle</Collapsible.Trigger>
    <Collapsible.Content>Content</Collapsible.Content>
  </Collapsible.Root>
</template>
import { Collapsible } from '@destyler-ui/react'

export function LazyMount() {
  return (
    <Collapsible.Root lazyMount>
      <Collapsible.Trigger>Toggle</Collapsible.Trigger>
      <Collapsible.Content>Content</Collapsible.Content>
    </Collapsible.Root>
  )
}
import { Collapsible } from '@destyler-ui/solid/collapsible'

export function LazyMount() {
  return (
    <Collapsible.Root lazyMount>
      <Collapsible.Trigger>Toggle</Collapsible.Trigger>
      <Collapsible.Content>Content</Collapsible.Content>
    </Collapsible.Root>
  )
}
<script lang="ts">import { Collapsible } from '@destyler-ui/svelte'</script>
<Collapsible.Root lazyMount><Collapsible.Trigger>Toggle</Collapsible.Trigger><Collapsible.Content>Content</Collapsible.Content></Collapsible.Root>

Unmount the content when the collapsible is closed.

<script setup lang="ts">
import { Collapsible } from '@destyler-ui/vue'
</script>

<template>
  <Collapsible.Root unmountOnExit>
    <Collapsible.Trigger>Toggle</Collapsible.Trigger>
    <Collapsible.Content>Content</Collapsible.Content>
  </Collapsible.Root>
</template>
import { Collapsible } from '@destyler-ui/react'

export function UnmountOnExit() {
  return (
    <Collapsible.Root unmountOnExit>
      <Collapsible.Trigger>Toggle</Collapsible.Trigger>
      <Collapsible.Content>Content</Collapsible.Content>
    </Collapsible.Root>
  )
}
import { Collapsible } from '@destyler-ui/solid/collapsible'

export function UnmountOnExit() {
  return (
    <Collapsible.Root unmountOnExit>
      <Collapsible.Trigger>Toggle</Collapsible.Trigger>
      <Collapsible.Content>Content</Collapsible.Content>
    </Collapsible.Root>
  )
}
<script lang="ts">import { Collapsible } from '@destyler-ui/svelte'</script>
<Collapsible.Root unmountOnExit><Collapsible.Trigger>Toggle</Collapsible.Trigger><Collapsible.Content>Content</Collapsible.Content></Collapsible.Root>

Combine lazy mounting with unmount on exit.

<script setup lang="ts">
import { Collapsible } from '@destyler-ui/vue'
</script>

<template>
  <Collapsible.Root lazyMount unmountOnExit>
    <Collapsible.Trigger>Toggle</Collapsible.Trigger>
    <Collapsible.Content>Content</Collapsible.Content>
  </Collapsible.Root>
</template>
import { Collapsible } from '@destyler-ui/react'

export function LazyMountAndUnmountOnExit() {
  return (
    <Collapsible.Root lazyMount unmountOnExit>
      <Collapsible.Trigger>Toggle</Collapsible.Trigger>
      <Collapsible.Content>Content</Collapsible.Content>
    </Collapsible.Root>
  )
}
import { Collapsible } from '@destyler-ui/solid/collapsible'

export function LazyMountAndUnmountOnExit() {
  return (
    <Collapsible.Root lazyMount unmountOnExit>
      <Collapsible.Trigger>Toggle</Collapsible.Trigger>
      <Collapsible.Content>Content</Collapsible.Content>
    </Collapsible.Root>
  )
}
<script lang="ts">import { Collapsible } from '@destyler-ui/svelte'</script>
<Collapsible.Root lazyMount unmountOnExit><Collapsible.Trigger>Toggle</Collapsible.Trigger><Collapsible.Content>Content</Collapsible.Content></Collapsible.Root>

Handle the exit complete event.

<script setup lang="ts">
import { Collapsible } from '@destyler-ui/vue'
</script>

<template>
  <Collapsible.Root @exit-complete="() => console.log('on exit')">
    <Collapsible.Trigger>Toggle</Collapsible.Trigger>
    <Collapsible.Content>Content</Collapsible.Content>
  </Collapsible.Root>
</template>
import { Collapsible } from '@destyler-ui/react'

export function OnExitComplete() {
  return (
    <Collapsible.Root onExitComplete={
      // eslint-disable-next-line no-alert
      () => alert('on exit')
    }
    >
      <Collapsible.Trigger>Toggle</Collapsible.Trigger>
      <Collapsible.Content>Content</Collapsible.Content>
    </Collapsible.Root>
  )
}
import { Collapsible } from '@destyler-ui/solid/collapsible'

export function OnExitComplete() {
  return (
    <Collapsible.Root onExitComplete={() => console.warn('on exit')}>
      <Collapsible.Trigger>Toggle</Collapsible.Trigger>
      <Collapsible.Content>Content</Collapsible.Content>
    </Collapsible.Root>
  )
}
<script lang="ts">import { Collapsible } from '@destyler-ui/svelte'</script>
<Collapsible.Root onExitComplete={() => console.log('on exit')}><Collapsible.Trigger>Toggle</Collapsible.Trigger><Collapsible.Content>Content</Collapsible.Content></Collapsible.Root>
<script setup lang="ts">
import { Collapsible, useCollapsible } from '@destyler-ui/vue'

const collapsible = useCollapsible()

</script>

<template>
    <span>{{ collapsible.visible ? 'Visible' : 'Hidden' }}</span>

    <Collapsible.RootProvider :value="collapsible">
      <Collapsible.Trigger>Toggle</Collapsible.Trigger>
      <Collapsible.Content>Content</Collapsible.Content>
    </Collapsible.RootProvider>
</template>
import { Collapsible, useCollapsible } from '@destyler-ui/react'

export function RootProvider() {
  const collapsible = useCollapsible()

  return (
    <>
      <span>{collapsible.visible ? 'Visible' : 'Hidden'}</span>

      <Collapsible.RootProvider value={collapsible}>
        <Collapsible.Trigger>Toggle</Collapsible.Trigger>
        <Collapsible.Content>Content</Collapsible.Content>
      </Collapsible.RootProvider>
    </>
  )
}
import { Collapsible, useCollapsible } from '@destyler-ui/solid/collapsible'

export function RootProvider() {
  const collapsible = useCollapsible()

  return (
    <>
      <span>{collapsible().visible ? 'Visible' : 'Hidden'}</span>

      <Collapsible.RootProvider value={collapsible}>
        <Collapsible.Trigger>Toggle</Collapsible.Trigger>
        <Collapsible.Content>Content</Collapsible.Content>
      </Collapsible.RootProvider>
    </>
  )
}
<script lang="ts">
  import { Collapsible, useCollapsible } from '@destyler-ui/svelte'
  const id = $props.id()
  const collapsible = useCollapsible({ id })
</script>
<span>{collapsible().visible ? 'Visible' : 'Hidden'}</span>
<Collapsible.RootProvider value={collapsible}><Collapsible.Trigger>Toggle</Collapsible.Trigger><Collapsible.Content>Content</Collapsible.Content></Collapsible.RootProvider>

Root

PropDefaultType
asChildfalse | true

Use the provided child element as the default rendered element, combining their props and behavior.

defaultOpenfalse | true

The initial open state of the collapsible when it is first rendered. Use when you do not need to control its open state.

disabledfalse | true

Whether the collapsible is disabled

idstring

The unique identifier of the machine.

idsPartial<{ root: string; content: string; trigger: string; }>

The ids of the elements in the collapsible. Useful for composition.

lazyMountfalsefalse | true

Whether to enable lazy mounting

openfalse | true

The controlled open state of the collapsible. Can be binded with v-model.

unmountOnExitfalsefalse | true

Whether to unmount on exit.

EmitEvent
exitComplete[]

Function called when the animation ends in the closed state.

openChange[details: OpenChangeDetails]

Function called when the popup is opened

update:open[open: boolean]

Event handler called when the open state of the collapsible changes.

Content

PropDefaultType
asChildfalse | true

Use the provided child element as the default rendered element, combining their props and behavior.

Context

No serializable props or emits are declared for this part.

RootProvider

PropDefaultType
value*Collapsible
asChildfalse | true

Use the provided child element as the default rendered element, combining their props and behavior.

Trigger

PropDefaultType
asChildfalse | true

Use the provided child element as the default rendered element, combining their props and behavior.

Root

PropDefaultType
asChildfalse | true

Use the provided child element as the default rendered element, combining their props and behavior.

defaultOpenfalse | true

The initial open state of the collapsible when it is first rendered. Use when you do not need to control its open state.

disabledfalse | true

Whether the collapsible is disabled

idsPartial<{ root: string; content: string; trigger: string; }>

The ids of the elements in the collapsible. Useful for composition.

lazyMountfalsefalse | true

Whether to enable lazy mounting

onExitComplete() => void

Function called when the animation ends in the closed state.

onOpenChange(details: collapsible.OpenChangeDetails) => void

Function called when the popup is opened

openfalse | true

Whether the collapsible is open

unmountOnExitfalsefalse | true

Whether to unmount on exit.

Content

PropDefaultType
asChildfalse | true

Use the provided child element as the default rendered element, combining their props and behavior.

Context

PropDefaultType
children*(context: UseCollapsibleContext) => ReactNode

RootProvider

PropDefaultType
value*UseCollapsibleReturn
asChildfalse | true

Use the provided child element as the default rendered element, combining their props and behavior.

Trigger

PropDefaultType
asChildfalse | true

Use the provided child element as the default rendered element, combining their props and behavior.

Root

PropDefaultType
asChild(props: (userProps?: solid_js419.JSX.HTMLAttributes<HTMLDivElement> | undefined) => JSX.HTMLAttributes<any>) => JSX.Element

Use the provided child element as the default rendered element, combining their props and behavior.

defaultOpenfalse | true

The initial open state of the collapsible when it is first rendered. Use when you do not need to control its open state.

disabledfalse | true

Whether the collapsible is disabled

idsPartial<{ root: string; content: string; trigger: string; }>

The ids of the elements in the collapsible. Useful for composition.

lazyMountfalsefalse | true

Whether to enable lazy mounting

onExitComplete() => void

Function called when the animation ends in the closed state.

onOpenChange(details: OpenChangeDetails) => void

Function called when the popup is opened

openfalse | true

Whether the collapsible is open

unmountOnExitfalsefalse | true

Whether to unmount on exit.

Content

PropDefaultType
asChild(props: (userProps?: solid_js419.JSX.HTMLAttributes<HTMLDivElement> | undefined) => JSX.HTMLAttributes<any>) => JSX.Element

Use the provided child element as the default rendered element, combining their props and behavior.

Context

PropDefaultType
children*(context: UseCollapsibleContext) => Element

RootProvider

PropDefaultType
value*UseCollapsibleReturn
asChild(props: (userProps?: solid_js419.JSX.HTMLAttributes<HTMLDivElement> | undefined) => JSX.HTMLAttributes<any>) => JSX.Element

Use the provided child element as the default rendered element, combining their props and behavior.

Trigger

PropDefaultType
asChild(props: (userProps?: solid_js419.JSX.ButtonHTMLAttributes<HTMLButtonElement> | undefined) => JSX.HTMLAttributes<any>) => JSX.Element

Use the provided child element as the default rendered element, combining their props and behavior.

Root

PropDefaultType
asChildimport("svelte").Snippet<[import("/home/runner/work/ui/ui/packages/svelte/dist/types").PropsFn<"div">]>
childrenSnippet<[]> | undefined
defaultOpenfalse | true
disabledfalse | true

Whether the collapsible is disabled

idstring
idsPartial<{ root: string; content: string; trigger: string; }>

The ids of the elements in the collapsible. Useful for composition.

lazyMountfalse | true

Whether the content should be lazy mounted

onExitComplete() => void

Callback fired when the animation ends

onOpenChange(details: import("/home/runner/work/ui/ui/packages/svelte/dist/index").CollapsibleOpenChangeDetails) => void

Function called when the popup is opened

openfalse | true

Whether the collapsible is open

unmountOnExitfalse | true

Whether the content should be unmounted when collapsed

Content

PropDefaultType
asChildimport("svelte").Snippet<[import("/home/runner/work/ui/ui/packages/svelte/dist/types").PropsFn<"div">]>
childrenSnippet<[]> | undefined

Context

PropDefaultType
renderSnippet<[UseCollapsibleContext]>

RootProvider

PropDefaultType
value*UseCollapsibleReturn
asChildimport("svelte").Snippet<[import("/home/runner/work/ui/ui/packages/svelte/dist/types").PropsFn<"div">]>
childrenSnippet<[]> | undefined

Trigger

PropDefaultType
asChildimport("svelte").Snippet<[import("/home/runner/work/ui/ui/packages/svelte/dist/types").PropsFn<"button">]>
childrenSnippet<[]> | undefined