Vue Bootstrap Collapse

Vue Collapse - Bootstrap 4 & Material Design

Vue Bootstrap collapse is a component which toggles content. Useful for grouping great amount of texts and/or graphics into expanding and collapsing items.


How it works

Collapse is used to show and hide content. Buttons or anchors are used as triggers that are mapped to specific elements you toggle. Collapsing an element will animate the height from it’s current value to 0. Given how CSS handles animations, you cannot use padding on a .collapse element. Instead, use the class as an independent wrapping element.


Example

Click the buttons below to show and hide another element:

You can use a link with the href attribute, or a button.

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

        <template>
          <mdb-container>
            <mdb-collapse :toggleTag="['a', 'button']" :togglers="2" :toggleClass="['btn btn-primary', 'btn-primary']" :toggleText="['Collapse link', 'Collapse button']">
              <h5 class="pt-3">Collapsing text</h5>
              <p class="pb-3">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</p>
            </mdb-collapse>
          </mdb-container>
        </template>
      

        <script>
          import { mdbCollapse, mdbContainer } from 'mdbvue';
          export default {
            name: 'CollapsePage',
            components: {
              mdbCollapse,
              mdbContainer
            }
          }
        </script>
      

Multiple targets

A <button> or <a> can show and hide multiple elements by referencing them with a JQuery selector in its href or data-target attribute. Multiple <button> or <a> can show and hide an element if they each reference it with their href or data-target attribute.

Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident.
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident.

        <template>
          <mdb-container>
            <mdb-btn color="primary" @click.native.prevent="collapse2 === true ? collapse2 = false : collapse2 = true">Toggle first element</mdb-btn>
            <mdb-btn color="primary" @click.native.prevent="collapse3 === true ? collapse3 = false : collapse3 = true">Toggle second element</mdb-btn>
            <mdb-btn color="primary" @click.native.prevent="[collapse2 === true ? collapse2 = false : collapse2 = true] && [collapse3 === true ? collapse3 = false : collapse3 = true]">Toggle both elements</mdb-btn>
            <mdb-row>
              <mdb-col sm="6">
                <transition @before-enter="beforeEnter" @enter="enter" @before-leave="beforeLeave">
                  <mdb-card v-if="collapse2" class="collapse-item mt-2">
                    <card-body>
                      <h5 class="pt-2">Collapsing text</h5>
                      <p class="pb-2">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</p>
                    </card-body>
                  </mdb-card>
                </transition>
              </mdb-col>
              <mdb-col sm="6">
                <transition @before-enter="beforeEnter" @enter="enter" @before-leave="beforeLeave">
                  <mdb-card v-if="collapse3" class="collapse-item mt-2">
                    <mdb-card-body>
                      <h5 class="pt-2">Collapsing text</h5>
                      <p class="pb-2">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</p>
                    </mdb-card-body>
                  </mdb-card>
                </transition>
              </mdb-col>
            </mdb-row>
          </mdb-container>
        </template>
      

        <script>
          import { mdbBtn, mdbContainer, mdbCol, mdbRow, mdbCard, mdbCardBody } from 'mdbvue';
          export default {
            name: 'CollapsePage',
            components: {
              mdbBtn,
              mdbContainer,
              mdbCol,
              mdbRow,
              mdbCard,
              mdbCardBody
            },
            data() {
              return {
                collapse2: false,
                collapse3: false
              };
            },
            methods: {
              beforeEnter(el) {
                this.elHeight = el.scrollHeight;
              },
              enter(el) {
                el.style.height = this.elHeight+'px';
              },
              beforeLeave(el) {
                el.style.height = 0;
              }
            }
          }
        </script>
      

        <style scoped>
          .collapse-item {
            overflow: hidden;
            height: 0;
            padding: 0;
            transition: height .5s;
          }
        </style>
      

Accordion MDB Pro component

Using the card component, you can extend the default collapse behavior to create an accordion.

Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.

        <template>
          <mdb-container>
            <mdb-accordion :panes="panes" material></mdb-accordion>
          </mdb-container>
        </template>
      

        <script>
          import { mdbContainer, mdbAccordion } from 'mdbvue';
          export default {
            components: {
              mdbContainer,
              mdbAccordion
            },
            data() {
              return {
                panes: [
                  {
                    title: 'Collapsible Group Item #1',
                    content: 'Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven\'t heard of them accusamus labore sustainable VHS.'
                  }, {
                    title: 'Collapsible Group Item #2',
                    content: 'Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven\'t heard of them accusamus labore sustainable VHS.'
                  },
                  {
                    title: 'Collapsible Group Item #3',
                    content: 'Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven\'t heard of them accusamus labore sustainable VHS.'
                  }
                ]
              }
            }
          }
        </script>
      

Collapse - API

In this section you will find advanced information about the Collapse component. You will learn which modules are required in this component, what are the possibilities of configuring the component, and what events and methods you can use in working with it.


Import statement


import { mdbCollapse } from 'mdbvue';
      

API Reference: Properties

Name Type Default Description Example
togglers Number 1 The number of toggle buttons. <mdb-collapse :togglers="2" ... >
toggleTag String, Array ['button'] Togglers tag <mdb-collapse :toggleTag="['a', 'button']" ... >
toggleText String, Array ['Toggle'] Determines the inner text of each toggler <mdb-collapse :toggleText="['Collapse link', 'Collapse button']" ... >
toggleClass String, Array ['btn btn-primary'] Determines the classes of each toggler <mdb-collapse :toggleClass="['Collapse link', 'Collapse button']" ... >

For Accordion API please visit Accordion Page.