Skip to content

Accordion

A simple vue accordion. Perfect for all your accordion, faq's scenarios.

Demo

Box style & Compact



  • 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.

Single bordered style & Individual Expandable

Custom Non-clickable header

  • 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.

Install

bash
npm i @vuesimple/vs-accordion

Usage

html
<template>
  <vs-accordion :is-box="true" is-compact>
    <vs-accordion-item v-for="(n, index) in [1, 2, 3]" :key="index">
      <!-- This slot will handle the title of the accordion and is the part you click on -->
      <template #accordion-trigger>
        <h4>Item {{ n }}</h4>
      </template>

      <!-- Default content -->
      <div>
        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.
      </div>
    </vs-accordion-item>
  </vs-accordion>
</template>

<script>
  import { VsAccordion, VsAccordionItem } from '@vuesimple/vs-accordion';

  export default {
    components: {
      VsAccordion,
      VsAccordionItem,
    },
  };
</script>

CDN

html
<script src="https://unpkg.com/@vuesimple/vs-accordion@<version>/dist/index.min.js"></script>

TIP

Replace <version> with a version number in the above url.

javascript
// Main/Entry file
app.use(VsAccordion.plugin);
html
<template>
  <vs-accordion :is-box="true" is-compact>
    <vs-accordion-item v-for="(n, index) in [1, 2, 3]" :key="index">
      <!-- This slot will handle the title of the accordion and is the part you click on -->
      <template #accordion-trigger>
        <h4>Item {{ n }}</h4>
      </template>

      <!-- Default content -->
      <div>
        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.
      </div>
    </vs-accordion-item>
  </vs-accordion>
</template>

Nuxt.js

Nuxt Code Snippet

After installation,

  • Create a file /plugins/vs-accordion.js

    javascript
    import Vue from 'vue';
    import { VsAccordion, VsAccordionItem } from '@vuesimple/vs-accordion';
    
    Vue.component('vs-accordion', VsTag);
  • Update nuxt.config.js

    javascript
    module.exports = {
      ...
      plugins: [
        { src: '~plugins/vs-accordion', mode: 'client' }
        ...
      ]
    }
  • In the page/ component

    html
    <template>
      <vs-accordion :is-box="true" is-compact>
        <vs-accordion-item v-for="(n, index) in [1, 2, 3]" :key="index">
          <!-- This slot will handle the title of the accordion and is the part you click on -->
          <template #accordion-trigger>
            <h4>Item {{ n }}</h4>
          </template>
    
          <!-- Default content -->
          <div>
            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.
          </div>
        </vs-accordion-item>
      </vs-accordion>
    </template>

Note

  • For older Nuxt versions, use <no-ssr>...</no-ssr> tag.
  • You can also do import { VsAccordion, VsAccordionItem } from '@vuesimple/vs-accordion' & add in component:{ VsAccordion, VsAccordionItem } and use it within component, without globally installing in plugin folder.

Props

VsAccordion

NameTypeDefaultDescription
activeNumber-Index of the accordion to be made active/visible. Starts from 0.
is-boxString-Box syle applied.
is-expandableBoolean-Enables simultaneous expansion of accordion sections.
levelBoolean-Sets aria-level heading rank in the document structure.
is-compactBoolean-Applies compact styling.
disable-animateBoolean-Disable toggle animation.

Events

VsAccordionItem

NameDescription
changeTriggered accordion open/close click { index: 0, visible: true }
openEmitted when the accordion starts to open. Listen for it using @open.
hideEmitted when the accordion close transition completes. Listen for it using @hide.

Slots

VsAccordion

You can define own item markup via slots:

NameDescription
(default)Default wrapper content for vs-accordion.
accordion-non-clickableNon-Clickable content inside header

VsAccordionItem

You can define own item markup via #slot-name:

NameDescription
accordion-triggerHeading content.
accordion-iconIcon content. If not present, default icon will be shown
(default)Default accordion content section for vs-accordion-item.