Used with a component · Collapsible
useCollapse
The height animation behind <Collapsible> and <AccordionItem>. It animates a panel between 0px and its content height through inline block-size, and the timing comes from your CSS transition. Once open and settled, the inline style is removed, so the panel follows later content changes. Content that grows while the panel opens retargets the animation instead of being clipped. Use it to collapse any element of your own; <Collapsible> adds the trigger, ARIA wiring and data-state.
Install
import { useCollapse } from 'vael-ui'Examples
<script setup lang="ts">
import { shallowRef, useTemplateRef } from 'vue'
import { useCollapse } from 'vael-ui'
const open = shallowRef(false)
const panelEl = useTemplateRef<HTMLElement>('panel')
const { style, state } = useCollapse(open, { el: panelEl })
</script>
<template>
<button :aria-expanded="open" @click="open = !open">Details</button>
<div ref="panel" class="panel" :style="style" :data-state="state">
<p>Shipping takes 3 to 5 days.</p>
</div>
</template>
<style scoped>
.panel { transition: block-size 200ms ease-out; }
</style>