Vue Collapsed

1.3.5 · active · verified Sun Apr 19

Vue Collapsed is a Vue 3 component that provides dynamic CSS height transitions, enabling smooth expansion and collapse animations for elements, typically used in accordions, collapsible panels, or reveal sections. It intelligently handles transitions to and from `height: auto`, which is traditionally challenging to animate natively with CSS transitions. The current stable version is 1.3.5, with frequent patch and minor releases addressing various edge cases, browser compatibility, and performance improvements, indicating an active development cadence. A key differentiator is its automatic calculation of optimal transition durations (`--vc-auto-duration`), which adapts to the element's height for a natural feel. It also offers robust support for custom CSS transitions and detailed animation control via `data-collapse` attributes, allowing for multi-property animations beyond just height. Furthermore, it includes specific optimizations and fixes for Server-Side Rendering (SSR) environments, aiming to minimize layout shifts and ensure consistent visual states on initial page load.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to import and use the <Collapse /> component within a Vue 3 setup script, toggling its visibility with a reactive state variable and providing extended content to showcase the transition.

<script setup lang="ts">
import { ref } from 'vue'
import { Collapse } from 'vue-collapsed'

const isExpanded = ref(false)
const longContent = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. '.repeat(5)
</script>

<template>
  <button @click="isExpanded = !isExpanded">Toggle Collapse</button>

  <Collapse :when="isExpanded">
    <p>{{ longContent }}</p>
  </Collapse>
</template>

<style>
  /* Optional: Custom transition example */
  .collapsed-area {
    transition: height 300ms ease-out;
  }
</template>

view raw JSON →