CSC Design System v4.0.1
VueFlavour Vue React Angular TypeScript
Flavour Vue React Angular TypeScript
PrimaryCSC UI Colors Primary Secondary AccentCustom Colors Red Orange Green Blue Purple Pink
CSC UI Colors Primary Secondary AccentCustom Colors Red Orange Green Blue Purple Pink
Guides Getting started Customization Data visualization Migration guide Componentsc-accordionc-alertc-autocompletec-badgec-breadcrumbc-buttonc-button-groupc-cardc-checkboxc-color-pickerc-csc-logoc-data-tablec-date-pickerc-dividerc-file-uploadc-iconc-icon-buttonc-linkc-listc-loaderc-login-buttonsc-login-cardc-mainc-menuc-messagec-modalc-navigation-buttonc-number-fieldc-otp-inputc-pagec-paginationc-popoverc-progress-barc-progress-circlec-radio-groupc-selectc-side-navigationc-sliderc-spinnerc-statusc-stepsc-switchc-tablec-tabsc-tagsc-text-fieldc-time-pickerc-toastsc-toolbarc-tooltipc-tree-select

<c-accordion>

A stack of collapsible sections, each a `c-accordion-item` whose header button shows or hides the content beneath it.

Usage

Give every item a heading and a value, and put its content in the item's default slot. The accordion's value names the expanded item.

<c-accordion v-model="expanded">
  <c-accordion-item heading="Project billing" value="billing">
    <p>Billing units are deducted monthly based on the resources in use.</p>
  </c-accordion-item>

  <c-accordion-item heading="Members and roles" value="members">
    <p>Invite members by email and assign them a role in the project.</p>
  </c-accordion-item>
</c-accordion>

When to use

  • To shorten a page of related sections the user reads one or a few at a time: questions and answers, groups of settings, the details behind a summary.
  • For switching between views of the same subject, use c-tabs, which shows one panel at a time.
  • Not for content the user must not miss or needs to compare side by side: collapsed content is easy to overlook.

Value

value is the expanded item's value, or null when every item is collapsed. Bind it with v-model, or set it and listen for change, which carries the new value each time the user toggles an item. Setting value from code expands and collapses items without firing an event.

Values compare strictly: an item value written as an attribute is a string, so value="2" does not match the number 2. An item without a value never expands.

Items must be direct children of the accordion; an item wrapped in another element is not expanded by it.

One or several expanded

By default one item is expanded at a time: expanding an item collapses the one that was open. With multiple, items open and close independently and value is an array of the expanded items' values. A single value counts as a one-item array, so the value attribute can name one item to start open; to open several from plain HTML, set the value property to an array.

mandatory keeps the last expanded item open: its header stops responding and reports itself disabled until another item is expanded. It never expands an item by itself, so give a mandatory accordion an initial value.

Headings and icons

heading sets the header's text. For richer content, such as a count beside the heading, use the item's heading slot, which replaces the prop. The icon slot shows an icon before the heading. Both slots render inside the header button, so they must not hold links, buttons or other interactive content.

Keyboard

Each header is a native button: Tab moves through the headers and the content of the expanded items, and Enter or Space toggles the focused header. A collapsed item's content is inert, so focus never lands in a hidden section.

Accessibility

The header button carries aria-expanded and aria-controls, and the content is a region labelled by its header. Headers are buttons, not heading elements, so items do not appear in the page's heading outline.

Customization

Collapsed items stack flush into one accordion frame with a shared hairline border and rounded ends. An expanded item lifts out of the frame with its own primary outline, a faint primary wash, an accent bar on its leading edge and space above and below. outlined adds a primary ring inside the expanded items' outline.

c-accordion::part(root) is the column holding the items. Each item has ::part(root) (its share of the frame, and the lifted box while expanded), ::part(header) (the toggle row), ::part(indicator) (the chevron) and ::part(content) (the card around the slotted content). The expanded custom state selects an expanded item:

c-accordion-item:state(expanded)::part(header),
c-accordion-item:state(expanded)::part(indicator) {
  color: var(--c-secondary);
}

<c-accordion-item>

One collapsible section of a c-accordion: a header button showing its heading (or the heading slot) and an optional icon, above the content in the default slot. Place it directly inside the accordion and give it a value: the accordion expands items by value and leaves an item without one collapsed.

The icon goes in the icon slot, before the heading. The item sizes it to 24px unless the c-icon sets its own size; a plain <svg> or <img> is sized the same.

Examples

Basic
Vue React Angular TypeScript
<template>
  <c-accordion v-model="expanded">
    <c-accordion-item heading="Project billing" value="billing">
      <p>Billing units are deducted monthly based on the resources in use.</p>
    </c-accordion-item>

    <c-accordion-item heading="Members and roles" value="members">
      <p>Invite members by email and assign them a role in the project.</p>
    </c-accordion-item>

    <c-accordion-item heading="Data storage" value="storage">
      <p>Allas object storage is available to every project by default.</p>
    </c-accordion-item>
  </c-accordion>
</template>

<script setup lang="ts">
import { ref } from 'vue';

const expanded = ref<'billing' | 'members' | 'storage' | null>('billing');
</script>
Custom style
Vue React Angular TypeScript
<template>
  <c-accordion v-model="expanded" class="custom-style">
    <c-accordion-item heading="Project billing" value="billing">
      <p>Billing units are deducted monthly based on the resources in use.</p>
    </c-accordion-item>

    <c-accordion-item heading="Members and roles" value="members">
      <p>Invite members by email and assign them a role in the project.</p>
    </c-accordion-item>

    <c-accordion-item heading="Data storage" value="storage">
      <p>Allas object storage is available to every project by default.</p>
    </c-accordion-item>
  </c-accordion>
</template>

<script setup lang="ts">
import { ref } from 'vue';

const expanded = ref<'billing' | 'members' | 'storage' | null>('billing');
</script>

<style>
/* The default look is the accordion frame; this recolours the expanded
   item from primary to secondary through its parts. */
c-accordion.custom-style {
  c-accordion-item:state(expanded) {
    &::part(root) {
      border-color: var(--c-secondary);
      background-color: color-mix(in srgb, var(--c-secondary) 5%, transparent);
      box-shadow: inset 2px 0 0 0 var(--c-secondary);
    }

    /* The heading takes the ink paired with the wash, as the default
       expanded heading does. */
    &::part(header) {
      color: var(--c-on-secondary-subtle);
    }

    &::part(indicator) {
      color: var(--c-secondary);
    }

    /* The header's hover and pressed washes follow the recolour too. */
    &::part(header):hover {
      background-color: color-mix(in srgb, var(--c-secondary) 8%, transparent);
    }

    &::part(header):active {
      background-color: color-mix(in srgb, var(--c-secondary) 15%, transparent);
    }

    &::part(content) {
      box-shadow: inset 0 0 0 1px
        color-mix(in srgb, var(--c-secondary) 25%, transparent);
    }
  }
}
</style>
Multiple
Vue React Angular TypeScript
<template>
  <div>
    <c-accordion multiple outlined>
      <c-accordion-item heading="Project billing" value="billing">
        <p>Billing units are deducted monthly based on the resources in use.</p>
      </c-accordion-item>

      <c-accordion-item heading="Members and roles" value="members">
        <p>Invite members by email and assign them a role in the project.</p>
      </c-accordion-item>

      <c-accordion-item heading="Data storage" value="storage">
        <p>Allas object storage is available to every project by default.</p>
      </c-accordion-item>
    </c-accordion>
  </div>
</template>
Basic · c-accordion-item
Vue React Angular TypeScript
<template>
  <div>
    <c-accordion>
      <c-accordion-item heading="Project billing" value="billing">
        <c-icon slot="icon" :path="mdiCreditCardOutline" />

        <p>Billing units are deducted monthly based on the resources in use.</p>
      </c-accordion-item>

      <c-accordion-item heading="Members and roles" value="members">
        <c-icon slot="icon" :path="mdiAccountGroup" />

        <p>Invite members by email and assign them a role in the project.</p>
      </c-accordion-item>

      <c-accordion-item heading="Data storage" value="storage">
        <c-icon slot="icon" :path="mdiDatabase" />

        <p>Allas object storage is available to every project by default.</p>
      </c-accordion-item>
    </c-accordion>
  </div>
</template>

<script setup lang="ts">
import { mdiAccountGroup, mdiCreditCardOutline, mdiDatabase } from '@mdi/js';
</script>
Custom heading · c-accordion-item
Vue React Angular TypeScript
<template>
  <div>
    <c-accordion>
      <c-accordion-item value="members">
        <div slot="heading" class="member-heading">
          <span>Members and roles</span>

          <span class="member-heading-meta">3 pending invites</span>
        </div>

        <p>Invite members by email and assign them a role in the project.</p>
      </c-accordion-item>

      <c-accordion-item heading="Data storage" value="storage">
        <p>Allas object storage is available to every project by default.</p>
      </c-accordion-item>
    </c-accordion>
  </div>
</template>

<style>
/* Slotted heading content is light DOM: style it with your own CSS. It
   inherits the header row's text color, so it matches a plain `heading`. */
.member-heading {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  font-weight: 500;
}

.member-heading-meta {
  font-size: 0.8125rem;
  font-weight: 400;
  color: var(--c-on-surface-muted);
}
</style>

API reference

<c-accordion>

A stack of collapsible sections, each a `c-accordion-item` whose header button shows or hides the content beneath it.

Properties

PropertyAttributeTypeDefaultDescription
mandatorymandatorybooleanfalse Keeps the last expanded item from collapsing: its header stops responding until another item expands. It never expands an item itself, so pair it with an initial `value`.
multiplemultiplebooleanfalse Lets items expand and collapse independently; `value` is then an array of the expanded items' values.
outlinedoutlinedbooleanfalse Adds a primary ring inside the outline of expanded items.
valuevalueCAccordionValuenull The expanded item's `value`, an array of them with `multiple`, or `null` when every item is collapsed.

Events

EventDetailDescription
changeCAccordionValueFired when the user toggles an item, carrying the new value: the expanded item's value, an array of values in `multiple` mode, or `null` when everything is collapsed.
inputvoidNative bubbling input event dispatched alongside every value change so a plain `v-model` stays in sync. Carries no detail.
update:valueCAccordionValueFired alongside `change` with the same detail — the `v-model` contract.

Slots

SlotDescription
defaultThe `c-accordion-item` elements, as direct children

CSS parts

Style from outside with c-accordion::part(name) — parts are the library's only styling customization API.

PartDescription
rootThe column holding the items

Types

Importable from the package root: import type { … } from '@cscfi/csc-ui'

CAccordionValue

Value of `c-accordion`: the expanded item's `value`, an array of them in `multiple` mode, or `null` when every item is collapsed.

export type CAccordionValue = (number | string)[] | null | number | string;

<c-accordion-item>

One collapsible section of a `c-accordion`: a header button showing its `heading` (or the `heading` slot) and an optional icon, above the content in the default slot. Place it directly inside the accordion and give it a `value`: the accordion expands items by value and leaves an item without one collapsed.

Properties

PropertyAttributeTypeDefaultDescription
headingheadingstring'' The header's text. The `heading` slot replaces it for rich content.
valuevaluenumber | string— Identifies the item in the parent `<c-accordion>`'s `value`. Required: the accordion leaves an item without one collapsed.

Slots

SlotDescription
headingRich heading content, replacing the `heading` prop; no interactive content
iconIcon shown in the header before the heading
defaultThe content shown while the item is expanded

CSS parts

Style from outside with c-accordion-item::part(name) — parts are the library's only styling customization API.

PartDescription
rootThe item's box: its share of the accordion frame, the lifted outline and tint while expanded, and the ring the accordion's `outlined` adds
headerThe toggle button row containing the icon, heading and indicator
indicatorThe rotating chevron at the end of the header
contentThe padded card around the slotted content inside the collapsing region

Custom states

Select on the host's live state with c-accordion-item:state(name) — combine with ::part() for per-state styling, e.g. c-accordion-item:state(checked)::part(indicator) targets the indicator only while checked.

StateDescription
expandedPresent while the item is expanded