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
javascriptimport Vue from 'vue'; import { VsAccordion, VsAccordionItem } from '@vuesimple/vs-accordion'; Vue.component('vs-accordion', VsTag);
Update
nuxt.config.js
javascriptmodule.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 incomponent:{ VsAccordion, VsAccordionItem }
and use it within component, without globally installing in plugin folder.
Props
VsAccordion
Name | Type | Default | Description |
---|---|---|---|
active | Number | - | Index of the accordion to be made active/visible. Starts from 0 . |
is-box | String | - | Box syle applied. |
is-expandable | Boolean | - | Enables simultaneous expansion of accordion sections. |
level | Boolean | - | Sets aria-level heading rank in the document structure. |
is-compact | Boolean | - | Applies compact styling. |
disable-animate | Boolean | - | Disable toggle animation. |
Events
VsAccordionItem
Name | Description |
---|---|
change | Triggered accordion open/close click { index: 0, visible: true } |
open | Emitted when the accordion starts to open. Listen for it using @open . |
hide | Emitted when the accordion close transition completes. Listen for it using @hide . |
Slots
VsAccordion
You can define own item markup via slots:
Name | Description |
---|---|
(default) | Default wrapper content for vs-accordion. |
accordion-non-clickable | Non-Clickable content inside header |
VsAccordionItem
You can define own item markup via #slot-name:
Name | Description |
---|---|
accordion-trigger | Heading content. |
accordion-icon | Icon content. If not present, default icon will be shown |
(default) | Default accordion content section for vs-accordion-item. |