Collapse

Reference

v-modelfalse
Boolean
Setting v-model to true reveals the collapsible element, false value hides it

nameempty string
String
Name of the component

transition"fade-collapse"
String
Sets an animation effect when showing or hiding collapsible element. Valid values are: 'fade-collapse' or empty string to disable animations. Animation speed can be set in the --collapse-transition-duration css variable.
Slots
reference
Slot for the content that triggers collapse. Slot props: isOpen, onTrigger

default
Slot for the content that is collapsed
Components
v-button-chevron
Optional version of v-button that has indicator build in. It uses the same props as v-button. Use v-button-chevron for minimal setup or normal v-button for more customizing options.

Notes

Collapse activation

You can activate collapse in two ways: by using reference slot or v-model. Slot is recommened as it takes minimal set up and can be done in template alone. v-model can still be used to programatically toggle collapse.

Accordion

You can wrap group of v-collapse components with v-accordion to create accordion. See example below.


Example

Model collapse

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

Reference slot collapse

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
fade-collapse
    <template>
  <!-- model collapse -->

  <p class="mt-8 mb-4">Model collapse</p>

  <v-card>
    <v-button-chevron
      :switch="example.isVisible"
      block
      :chevron="{ class: 'ml-auto' }"
      @click="example.isVisible = !example.isVisible"
    >
      Toggle collapse
    </v-button-chevron>

    <v-collapse
      v-model="example.isVisible"
      :transition="example.transition"
    >
      <div class="p-8">
        {{ text[0] }}
      </div>
    </v-collapse>
  </v-card>

  <!-- reference slot collapse -->

  <p class="mt-8 mb-4">Reference slot collapse</p>

  <v-card>
    <v-collapse :transition="example.transition">
      <template #reference="{ isOpen, onTrigger }">
        <v-button-chevron
          :switch="isOpen"
          block
          :chevron="{ class: 'ml-auto' }"
          v-on="onTrigger"
        >
          Toggle collapse
        </v-button-chevron>
      </template>

      <div class="p-8">
        {{ text[0] }}
      </div>
    </v-collapse>
  </v-card>

</template>
  
    <script setup>
import { reactive } from "vue";
import { text } from "../example-data/data.js";

let example = reactive({
  isVisible: false,
  transition: "fade-collapse",
});
</script>
  

Example - accordion

Turn collapse components to accordion by wrapping them with v-accordion component. In accordion mode only one collapse element can be open.

Accordion - controlled by models

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32. The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.

Accordion - controlled from reference slot

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
    <template>
  <!-- model collapse accordion -->

  <p class="mb-4 mt-8">Accordion - controlled by models</p>

  <v-accordion class="my-2">
    <v-card>
      <v-button-chevron
        :switch="accordion.isVisible"
        block
        :chevron="{ class: 'ml-auto' }"
        @click="accordion.isVisible = !accordion.isVisible"
      >
        Toggle collapse
      </v-button-chevron>
      <v-collapse v-model="accordion.isVisible">
        <div class="p-8">
          {{ text[0] }}
        </div>
      </v-collapse>
    </v-card>

    <v-card class="my-2">
      <v-button-chevron
        :switch="accordion.isVisible2"
        block
        :chevron="{ class: 'ml-auto' }"
        @click="accordion.isVisible2 = !accordion.isVisible2"
      >
        Toggle collapse
      </v-button-chevron>
      <v-collapse v-model="accordion.isVisible2">
        <div class="p-8">
          {{ text[1] }}
        </div>
      </v-collapse>
    </v-card>

    <v-card class="my-2">
      <v-button-chevron
        :switch="accordion.isVisible3"
        block
        :chevron="{ class: 'ml-auto' }"
        @click="accordion.isVisible3 = !accordion.isVisible3"
      >
        Toggle collapse
      </v-button-chevron>
      <v-collapse v-model="accordion.isVisible3">
        <div class="p-8">
          {{ text[2] }}
        </div>
      </v-collapse>
    </v-card>
  </v-accordion>

  <!-- reference slot accordion -->

  <p class="mb-4 mt-8">Accordion - controlled from reference slot</p>

  <v-accordion class="my-2">
    <v-card mod-card="shape:square">
      <v-collapse>
        <template #reference="{ isOpen, onTrigger }">
          <v-button-chevron
            :switch="isOpen"
            mod-button="preset:plain"
            block
            class="p-3"
            :chevron="{ class: 'ml-auto' }"
            v-on="onTrigger"
          >
            Toggle collapse
          </v-button-chevron>
        </template>
        <div class="p-8">
          {{ text[0] }}
        </div>
      </v-collapse>
    </v-card>

    <v-card
      mod-card="shape:square"
      class="my-2"
    >
      <v-collapse>
        <template #reference="{ isOpen, onTrigger }">
          <v-button-chevron
            :switch="isOpen"
            mod-button="preset:plain"
            block
            class="p-3"
            :chevron="{ class: 'ml-auto' }"
            v-on="onTrigger"
          >
            Toggle collapse
          </v-button-chevron>
        </template>
        <div class="p-8">
          {{ text[1] }}
        </div>
      </v-collapse>
    </v-card>

    <v-card
      mod-card="shape:square"
      class="my-2"
    >
      <v-collapse>
        <template #reference="{ isOpen, onTrigger }">
          <v-button-chevron
            :switch="isOpen"
            mod-button="preset:plain"
            block
            class="p-3"
            :chevron="{ class: 'ml-auto' }"
            v-on="onTrigger"
          >
            Toggle collapse
          </v-button-chevron>
        </template>
        <div class="p-8">
          {{ text[0] }}
        </div>
      </v-collapse>
    </v-card>
  </v-accordion>
</template>
  
    <script setup>
import { reactive } from "vue";
import { text } from "../example-data/data.js";

let accordion = reactive({
  isVisible: false,
  isVisible2: false,
  isVisible3: false,
});
</script>