Skip to content
LIBRARYBase

Accordion ​

MAccordion groups related sections under individual headers. The app owns which sections are open and supplies each body through a scoped slot.

Availability

Accordion is available since 0.1.0-alpha.4; intrinsic Reveal height ships in alpha.6. Forma adds the source validation described below.

Web preview
Open example ↗

Usage ​

vue
<script setup lang="ts">
import { ref } from 'vue'
import type { ChoiceValue } from '@getcortexlabs/mavis-core'
const expanded = ref<ChoiceValue[]>([])
const items = [{ value: 'delivery', title: 'When will it arrive?', icon: 'package' }] as const
</script>

<template>
  <m-accordion v-model="expanded" :items="items" label="Delivery questions">
    <template #default="{ item }">
      <m-text v-if="item.value === 'delivery'">Check the date in your order.</m-text>
    </template>
  </m-accordion>
</template>

Props ​

PropTypeDefaultBehavior
itemsreadonly AccordionItem[]requiredUnique value, nonempty title, optional description, icon and disabled.
modelValuereadonly ChoiceValue[][]Expanded values; always an array.
multiplebooleanfalseAllows more than one open section.
labelstringrequiredNonempty accessible group name.
expandedLabel / collapsedLabelstringExpanded / CollapsedNonempty native state descriptions; translate in the app.
disabledbooleanfalseDisables all headers. Body controls remain app-owned.
width / grow / shrinkdimension / number / numberauto / 0 / contextLayout participation.
id / accessibilityHiddenstring / boolean— / falseIdentifier and accessibility exclusion.

Values are strings or finite numbers; 0 and '0' are distinct. Duplicate item or expanded values throw RangeError. Invalid values or missing labels throw TypeError. More than one expanded value in single mode throws RangeError; trim the array before switching off multiple. Unknown values remain in the model but render no matching body. Removing an item never silently rewrites the app's state.

State and composition ​

update:modelValue requests a new array without mutating the original. Closing the only open section produces []. Disabled headers emit nothing, including when their body is already open. The app may accept or reject every request.

The default slot receives { item }. A body mounts when opened and unmounts after the Reveal exit. Keep form values or data that must survive closing in the parent. Body controls are separate actions; headers cannot contain custom buttons. Titles and descriptions wrap naturally.

The chevron turns with a spring and the item's icon bumps when it opens. The body arrives with a short lift after the height starts to grow; the arrival wrapper is released once it settles, so application content keeps no transform. Content already open at mount appears without motion. Web headers also get a hover surface and a slight press.

Reveal uses Jolt animateSize on Web and NativeScript to animate between zero and intrinsic height, alongside opacity. It keeps closing content mounted but unavailable for interaction, reverses from the current size, and releases height to auto after opening. Content and parent-width changes then follow normal layout. Reduced motion settles the transition; unload/unmount cancels owned playback. See Forma for a dynamic body and editable draft.

Keyboard and focus ​

Web headers are buttons inside headings, with aria-expanded and a labelled body region when open. Enter/Space toggles a section. Up/Down, Home and End move between enabled headers without expanding them. Closing or removing a body containing focus returns focus to an available header; disabling the whole group leaves the browser's normal focus behavior.

Native headers expose their title, description, group hint and translated expanded/collapsed value through the existing ListItem interaction. Actual VoiceOver/TalkBack speech follows platform settings. Native keyboard navigation uses the platform's focus system. Hardware keyboard and physical-device audits remain separate from simulator checks.

Help center keeps expanded values per topic and feedback in the parent.

Full example ​

View source
vue
<script setup lang="ts">
import { useCatalogLocale } from '../locale'
import { computed, ref } from 'vue'
import type { AccordionItem, ChoiceValue } from '@getcortexlabs/mavis-core'

const { t, locale } = useCatalogLocale(() => props.lang)

const props = withDefaults(defineProps<{ lang?: 'en' | 'pt' }>(), { lang: undefined })

const pt = computed(() => (props.lang ?? locale.value) === 'pt')
const expanded = ref<ChoiceValue[]>(['start'])
const multiple = ref(false)
const disabled = ref(false)
const helpful = ref(false)
const items = computed<AccordionItem[]>(() => [
  {
    value: 'start',
    title: pt.value ? 'Por onde eu começo?' : 'Where do I start?',
    description: pt.value ? 'Seu primeiro passo, sem complicar.' : 'A simple first step.',
    icon: 'sparkles',
  },
  {
    value: 'theme',
    title: pt.value ? 'Posso mudar o visual?' : 'Can I change the look?',
    icon: 'palette',
  },
  {
    value: 'offline',
    title: pt.value ? 'E quando eu ficar offline?' : 'What about going offline?',
    icon: 'download',
  },
  {
    value: 'soon',
    title: pt.value ? 'O que vem depois?' : 'What comes next?',
    description: pt.value
      ? 'Esta seção ainda não está disponível.'
      : 'This section is not available yet.',
    disabled: true,
  },
])
const answers = computed<Record<string, string>>(() =>
  pt.value
    ? {
        start:
          'Escolha uma ideia pequena e dê forma a ela. Você pode ajustar cada detalhe ao longo do caminho.',
        theme:
          'Os componentes acompanham a paleta e a tipografia do tema. Experimente a troca de tema no topo desta página.',
        offline:
          'O app decide quais dados ficam no dispositivo. O Accordion apenas organiza as respostas na tela.',
      }
    : {
        start: 'Choose a small idea and give it shape. You can refine each detail along the way.',
        theme:
          'Components follow the theme palette and typography. Try the theme switch at the top of this page.',
        offline:
          'The app decides which data stays on the device. Accordion simply organizes the answers on screen.',
      },
)
function setMultiple(value: boolean) {
  if (!value) expanded.value = expanded.value.slice(0, 1)
  multiple.value = value
}
</script>
<template>
  <m-column id="accordion-demo" gap="lg">
    <m-column gap="sm">
      <m-text variant="overline" tone="primary">{{
        t(pt ? 'ESPAÇO PARA DESCOBRIR' : 'ROOM TO DISCOVER')
      }}</m-text>
      <m-text variant="title">{{
        t(pt ? 'Uma pergunta abre caminhos.' : 'A question opens possibilities.')
      }}</m-text>
      <m-text tone="muted">{{
        t(
          pt
            ? 'Encontre uma resposta. Explore a próxima quando quiser.'
            : 'Find an answer. Explore the next one when you are ready.',
        )
      }}</m-text>
    </m-column>
    <m-accordion
      v-model="expanded"
      :items="items"
      :multiple="multiple"
      :disabled="disabled"
      :label="t(pt ? 'Perguntas frequentes' : 'Frequently asked questions')"
      :expandedLabel="pt ? 'Expandido' : 'Expanded'"
      :collapsedLabel="pt ? 'Recolhido' : 'Collapsed'"
    >
      <template #default="{ item }">
        <m-column gap="md">
          <m-text>{{ t(answers[item.value]) }}</m-text>
          <m-button
            v-if="item.value === 'start'"
            variant="secondary"
            size="sm"
            @click="helpful = !helpful"
            >{{
              t(
                helpful
                  ? pt
                    ? 'Obrigado pelo retorno'
                    : 'Thanks for the feedback'
                  : pt
                    ? 'Foi útil'
                    : 'Helpful',
              )
            }}</m-button
          >
        </m-column>
      </template>
    </m-accordion>
    <m-switch
      :modelValue="multiple"
      :label="t(pt ? 'Várias seções abertas' : 'Multiple open sections')"
      @update:modelValue="setMultiple"
    />
    <m-switch v-model="disabled" :label="t(pt ? 'Bloquear cabeçalhos' : 'Disable headers')" />
  </m-column>
</template>

Desktop ​

Each header is a native button that opens its panel through v-model, and Up, Down, Home and End move between headers. The panel fades in as on the other renderers; its height does not animate. See Desktop components.

Components for NativeScript and Web. Starting with Vue.