Collapsible
Show or hide a single section of content.
Demos
Size
DisabledUnmount on hide
Usage
vue
<script setup lang="ts">
import { Accordion } from '~/components/ui/accordion'
const items = [
{ value: 'source', label: 'Do I own the source?', content: 'Yes. Copy and adapt the files.' },
]
</script>
<template>
<Accordion :items="items" />
</template>
Use the content slot for the expandable body. Header height, icon, text, radius, and body padding follow the selected size. Expansion respects reduced motion.
Appearance and sizing
A single rounded border contains the disclosure. It uses the same header and body spacing as Accordion. The open header has a light tint, and body text aligns with its label. Focus stays inside the outer border.
| Size | Header height | Horizontal padding | Text | Icon |
|---|---|---|---|---|
| xs | 40px | 12px | 12px | 12px |
| sm | 44px | 16px | 13px | 14px |
| md | 48px | 20px | 14px | 16px |
| lg | 52px | 24px | 14px | 18px |
| xl | 56px | 28px | 16px | 20px |
These headers have 16px more height than compact controls to support longer labels and the expanded body. Coarse-pointer targets stay at least 44px tall.
Installation
Complete the shared installation. Copy Collapsible.vue and index.ts into app/components/ui/collapsible/.
app/components/ui/collapsible/Collapsible.vue
<script setup lang="ts">
import { Accordion as Primitive } from 'akaza-ui'
import { computed, useAttrs } from 'vue'
import { cn } from '../../../utils/ui'
import uiConfig from '../ui.config'
import {
accordionVariants,
resolveAccordionVariants,
type AccordionProps,
type AccordionSlots,
} from './index'
defineOptions({ inheritAttrs: false })
// Preserve Akaza defaults when optional props, including Boolean aliases, are omitted.
const props = withDefaults(defineProps<AccordionProps>(), {
valueKey: undefined,
labelKey: undefined,
contentKey: undefined,
disabledKey: undefined,
type: undefined,
collapsible: true,
disabled: undefined,
orientation: undefined,
unmountOnHide: undefined,
as: undefined,
ui: undefined,
modelValue: undefined,
})
defineSlots<AccordionSlots>()
const attrs = useAttrs()
const styles = computed(() => accordionVariants(resolveAccordionVariants(props, uiConfig)))
const mergedUi = computed(() => {
const overrides = props.ui as Record<string, string | undefined> | undefined
return Object.fromEntries(
Object.entries(styles.value).map(([part, style]) => [
part,
cn(style(), overrides?.[part], part === 'root' ? props.class : undefined),
]),
)
})
const primitiveProps = computed(() => {
const { class: _class, ui: _ui, size: _size, ...native } = props
return native
})
</script>
<template>
<component :is="Primitive" v-bind="{ ...primitiveProps, ...attrs }" :ui="mergedUi">
<template v-for="(_, name) in $slots" #[name]="scope"
><slot :name="name as keyof AccordionSlots" v-bind="scope ?? {}"
/></template>
</component>
</template>
API
Variants and defaults
| Prop | Values | Default |
|---|---|---|
size | xs, sm, md, lg, xl | sm |
Props
| Prop | Type | Default | Description |
|---|---|---|---|
modelValue | boolean | false | Controlled open state through v-model. |
size | "xs" | "sm" | "md" | "lg" | "xl" | "sm" | Coordinated header and content sizing. Shared UI configuration can override the default. |
class | HTMLAttributes['class'] | — | Classes merged into the root recipe. |
disabled | boolean | false | Prevents the panel from being toggled. |
unmountOnHide | boolean | false | Remove content from the DOM when closed. |
as | string | "div" | Root element tag. |
ui | CollapsibleUi | — | CSS class overrides. |
Slots
| Slot | Scoped props | Description |
|---|---|---|
trigger | { isOpen, open, close, toggle } | The toggle trigger element. |
icon | { isOpen } | Indicator icon inside the trigger. |
content | { isOpen, close } | The collapsible panel body. |
Events
| Event | Payload | Description |
|---|---|---|
update:modelValue | [open: boolean] | Updates the controlled open state. |
open-change | [open: boolean, details] | Fired when the open state changes. |
Exposed methods
| Method | Signature | Description |
|---|---|---|
open | (reason?, event?) => void | Opens the panel. |
close | (reason?, event?) => void | Closes the panel. |
toggle | (reason?, event?) => void | Toggles the panel. |
Keyboard
| Key | Behavior |
|---|---|
Enter / Space | Toggles focused trigger through native button behavior. |
Tab / Shift + Tab | Uses native order. Closed content is inert and cannot receive focus. |