Skip to content

Collapsible

A collapsible panel controlled by a button.

Anatomy

Import the component and assemble its parts:

vue
<script setup>
import { CollapsiblePanel, CollapsibleRoot, CollapsibleTrigger } from 'base-ui-vue'
</script>

<template>
  <CollapsibleRoot>
    <CollapsibleTrigger />
    <CollapsiblePanel />
  </CollapsibleRoot>
</template>

Animations

The Collapsible panel can be animated using CSS transitions or CSS animations via the --collapsible-panel-height and --collapsible-panel-width CSS variables combined with data-starting-style and data-ending-style data attributes.

css
.Panel {
  height: var(--collapsible-panel-height);
  overflow: hidden;
  transition: all 150ms ease-out;
}

.Panel[data-starting-style],
.Panel[data-ending-style] {
  height: 0;
}

Controlled state

Use the open prop and open-change event for controlled behavior:

vue
<script setup>
import { CollapsiblePanel, CollapsibleRoot, CollapsibleTrigger } from 'base-ui-vue'
import { ref } from 'vue'

const open = ref(false)

function handleOpenChange(value, details) {
  open.value = value
}
</script>

<template>
  <CollapsibleRoot :open="open" @open-change="handleOpenChange">
    <CollapsibleTrigger>Toggle</CollapsibleTrigger>
    <CollapsiblePanel>Content</CollapsiblePanel>
  </CollapsibleRoot>
</template>

API reference

Root

Groups all parts of the collapsible. Renders a <div> element.

PropTypeDefaultDescription
asstring | Component'div'The element or component to use for the root node.
openbooleanundefinedWhether the collapsible panel is currently open (controlled).
default-openbooleanfalseWhether the collapsible panel is initially open (uncontrolled).
disabledbooleanfalseWhether the component should ignore user interaction.
classstring | ((state: State) => string)undefinedCSS class applied to the element, or a function that returns a class based on the component's state.
styleStyleValue | ((state: State) => StyleValue)undefinedStyle applied to the element, or a function that returns a style object based on the component's state.
EmitsTypeDescription
open-change(open: boolean, details: EventDetails)Emitted when the panel is opened or closed.

Trigger

A button that opens and closes the collapsible panel. Renders a <button> element.

PropTypeDefaultDescription
asstring | Component'button'The element or component to use for the root node.
disabledbooleanundefinedWhether the trigger should ignore user interaction. When undefined, inherits from CollapsibleRoot.
native-buttonbooleantrueWhether the component renders a native <button> element.
classstring | ((state: State) => string)undefinedCSS class applied to the element, or a function that returns a class based on the component's state.
styleStyleValue | ((state: State) => StyleValue)undefinedStyle applied to the element, or a function that returns a style object based on the component's state.
AttributeDescription
data-panel-openPresent when the collapsible panel is open.

Panel

A panel with the collapsible contents. Renders a <div> element.

PropTypeDefaultDescription
asstring | Component'div'The element or component to use for the root node.
idstringundefinedThe id attribute of the panel element. When set, overrides the auto-generated panel id.
keep-mountedbooleanfalseWhether to keep the element in the DOM while the panel is hidden.
hidden-until-foundbooleanfalseAllows the browser's built-in page search to find and expand the panel contents. Overrides keep-mounted and uses hidden="until-found".
classstring | ((state: State) => string)undefinedCSS class applied to the element, or a function that returns a class based on the component's state.
styleStyleValue | ((state: State) => StyleValue)undefinedStyle applied to the element, or a function that returns a style object based on the component's state.
AttributeDescription
data-openPresent when the collapsible panel is open.
data-closedPresent when the collapsible panel is closed.
data-starting-stylePresent when the panel is animating in.
data-ending-stylePresent when the panel is animating out.
CSS VariableDescription
--collapsible-panel-heightThe collapsible panel's height.
--collapsible-panel-widthThe collapsible panel's width.