vael-ui v0.5.7

Layout & structure

Layout

Collapsible

A single section that shows and hides its content. Use it for optional or secondary content.

Install

import { Collapsible } from 'vael-ui'

Playground

Usage
<script setup lang="ts">
import { ref } from 'vue'
import { Collapsible, Button } from 'vael-ui'

const open = ref(false)
</script>

<template>
  <Collapsible v-model:open="open">
    <template #trigger>
      <Button variant="outline">{{ open ? 'Close' : 'Open' }}</Button>
    </template>
    <p>Toggle to reveal this content.</p>
  </Collapsible>
</template>

Props

NameTypeDefaultDescription
disabledbooleanfalseBlocks toggling and marks the trigger aria-disabled.
motionCollapsibleMotiontrueHow it moves: its appearance ({ initial: { panel: { opacity: 0 } } }) and its states ({ states: { open: { trigger: { opacity: 0.7 } } } }). false skips the height transition; use the exposed panelEl for your own.
uiPartial<Record<'root' | 'trigger' | 'panel' | 'body', UiPartValue>>Class and style overrides for each part.
openbooleanfalseWhether the panel is open.

Events

NameTypeDescription
update:open(value: boolean)Fires when open changes (v-model:open).

Slots

NameTypeDescription
trigger{ open: boolean; }Toggle control: clicks toggle the panel, and its first button receives aria-expanded and aria-controls.
defaultanyPanel content.

Exposed

NameTypeDescription
elHTMLElement | nullRoot element.
panelElHTMLElement | nullPanel element, always mounted.
partsRecord<string, HTMLElement | HTMLElement[] | null>Its elements by part name, for your own animation; a repeated part is an array.

Motion New

Collapsible: its appearance and states. */ type CollapsibleHook = MotionHook< CollapsiblePart | 'body', { signal: AbortSignal; reducedMotion: boolean } > /** Collapsible: its appearance and states, and your own opening and closing. With a hook its height no longer eases: enter runs once the panel is open (animate it from closed), and leave before it closes, which waits for what it returns.

<Collapsible
  :motion="{ states: { open: { panel: { scale: 1.04 } } } }"
/>
NameTypeDescription
initialexitroottriggerpanelSets where each part comes in from and leaves to: any CSS property, plus x, y and blur. A plain number is px, or degrees for rotate.
statesopendisabledSets values per part that hold while a state is on. An array is a set of keyframes that plays once as the state turns on, such as a shake on invalid.
enterleave(parts, context) => animationAnimates the parts with GSAP, motion or element.animate(). Return the animation and the component waits for it, and stops it if interrupted.
springdurationeasing{ damping, response } | number | stringTimes all of it: a spring, or a duration in ms with an easing. Never both.
falsebooleanTurns its motion off, for an animation of your own on its exposed elements.

Accessibility

Follows the Disclosure pattern from the WAI-ARIA Authoring Practices Guide.

KeyAction
EnterSpaceOpens or closes the panel from the trigger button.
  • Put a <button> in the #trigger slot. The first button, [role="button"] or a[href] in it gets aria-expanded and aria-controls.
  • Keyboard support comes from the element you put in the slot. The wrapper around it only listens for clicks.
  • With disabled, the trigger gets aria-disabled="true" and clicks do nothing.
  • The panel has role="region", named by the trigger. A closed panel stays mounted as hidden="until-found": out of the tab order and the accessibility tree, but the browser's find reaches it and opens it. Where a browser has no until-found, it is aria-hidden and inert instead.