Skip to content

Accordion component

The Accordion component designed with Vue 3 and Tailwind CSS. It includes expandable and collapsible content sections.

Basic Usage

Import and use Accordion in your Vue components as follows:

vue
<template>
  <Accordion :items="accordionItems" name="Accordion 1"/>
</template>

<script setup>
import { Accordion } from '@robuust-digital/vue-components/core';

const accordionItems = [
  {
    title: 'Title 1',
    content: 'Content 1',
  },
  {
    title: 'Title 2',
    content: 'Content 2 <a href="/">containing a anchor</a>',
  },
  {
    title: 'Title 3',
    content: 'Content 3',
  },
];
</script>
Title 1
Content 1
Title 2
Title 3
Content 3

Props

Below are the props supported by Accordion, which allow you to customize its appearance and behavior:

PropTypeDefaultDescription
itemsArray, ObjectRequiredSet the array with items containing title and content text.
nameStringundefinedSet a name to only allow a single item opened at the same time
defaultOpenIndexNumber, String0Set the index of the active open item.
contentClassString''Set a class for the content wrapper. (e.g .wysiwyg or .prose for rich text styling)

CSS Customization ⚡️

To customize the accordion styles global

css
/* Available variables */
:root {
  --rvc-accordion-border-width: var(--rvc-base-border-width);
  --rvc-accordion-border-style: var(--rvc-base-border-style);
  --rvc-accordion-border-color: var(--rvc-base-border-color);
  --rvc-accordion-padding-y: calc(var(--spacing) * 6);
  --rvc-accordion-font-weight: var(--font-weight-normal);
  --rvc-accordion-font-size: var(--text-base);
  --rvc-accordion-color: var(--color-slate-600);
  --rvc-accordion-summary-font-weight: var(--font-weight-medium);
  --rvc-accordion-summary-font-size: var(--text-lg);
  --rvc-accordion-summary-color: var(--color-black);
  --rvc-accordion-summary-decoration-hover: underline;
}

/* Or customize the class with CSS props (not recommended) */
.rvc-accordion {
  details {
    cursor: pointer;
  }
}

Example

Default Accordion

Title 1
Content 1
Title 2
Title 3
Content 3
Show code
vue
<Accordion :items="accordionItems" name="Accordion 1"/>