Collapsible
Overview
Collapsible is a headless @vyui/core primitive for a single show/hide region toggled by a trigger. It is the one-region building block that the Accordion composes for multiple coordinated sections.
@vyui/core — behavior only. For a styled multi-section disclosure, use VyAccordion from @vyui/kit.Anatomy
<CollapsibleRoot>
<CollapsibleTrigger />
<CollapsibleContent />
</CollapsibleRoot>
Usage
<script setup lang="ts">
import {
CollapsibleContent,
CollapsibleRoot,
CollapsibleTrigger,
} from '@vyui/core'
const open = ref(false)
</script>
<template>
<CollapsibleRoot v-model:open="open">
<CollapsibleTrigger>
<text>{{ open ? 'Hide details' : 'Show details' }}</text>
</CollapsibleTrigger>
<CollapsibleContent>
<view class="p-4">
<text>Collapsible body content.</text>
</view>
</CollapsibleContent>
</CollapsibleRoot>
</template>
Features and behavior
open/v-model:opencontrols the state;defaultOpenseeds uncontrolled state.disabledprevents the trigger from toggling.unmountOnHide(defaulttrue) removes the content from the rendered tree when closed.CollapsibleTriggerreflects the open state through a data/ui state hook for styling.
API
CollapsibleRoot
| Prop | Default | Type |
|---|---|---|
as | — | AsTag | Component | undefinedThe element or component this component should render as. Can be overwritten by `asChild`. |
asChild | — | boolean | undefinedChange the default rendered element for the one passed as a child, merging their props and behavior. Use this when you need a component to render through a child element while keeping the primitive's props and behavior. |
defaultOpen | false | boolean | undefinedThe open state of the collapsible when it is initially rendered. <br> Use when you do not need to control its open state. |
disabled | — | boolean | undefinedWhen `true`, prevents the user from interacting with the collapsible. |
open | undefined | boolean | undefinedThe controlled open state of the collapsible. Can be bound with `v-model`. |
unmountOnHide | true | boolean | undefinedWhen `true`, the element will be unmounted on closed state. |
| Event | Payload |
|---|---|
update:open | [value: boolean] |
CollapsibleTrigger
| Prop | Default | Type |
|---|---|---|
as | "view" | AsTag | Component | undefinedThe element or component this component should render as. Can be overwritten by `asChild`. |
asChild | — | boolean | undefinedChange the default rendered element for the one passed as a child, merging their props and behavior. Use this when you need a component to render through a child element while keeping the primitive's props and behavior. |
CollapsibleContent
| Prop | Default | Type |
|---|---|---|
as | — | AsTag | Component | undefinedThe element or component this component should render as. Can be overwritten by `asChild`. |
asChild | — | boolean | undefinedChange the default rendered element for the one passed as a child, merging their props and behavior. Use this when you need a component to render through a child element while keeping the primitive's props and behavior. |
forceMount | — | boolean | undefined |
Accessibility
- The trigger exposes native button semantics and announces
collapsed/expanded. - A disabled trigger is announced as disabled.
- Keep the trigger label descriptive of the region it controls.