vael-ui v0.5.7

Selection

Layout

CascadeSelect

A dropdown for picking a path through nested options, one level at a time. Use it for categories or places that branch into smaller ones.

Validating a form? vael-form wires this up with a schema

Install

import { CascadeSelect } from 'vael-ui'

Playground

Choose an option

Placement, behaviour and animation

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

const items = [
  { label: 'src', value: 'src', children: [
    { label: 'App.vue', value: 'src/App.vue' },
    { label: 'main.ts', value: 'src/main.ts' },
  ] },
  { label: 'README.md', value: 'README.md' },
]
const value = ref<V>()
const open = ref(false)
</script>

<template>
  <CascadeSelect
    placeholder="Choose an option"
    aria-label="Project files"
    :items="items"
    v-model="value"
    v-model:open="open"
  />
</template>

Props

NameTypeDefaultDescription
itemsRequiredreadonly T[]Tree of options; only leaves (nodes without children) can be selected.
placeholderstringText shown in the trigger when nothing is selected.
multiplebooleanfalseSelects several leaves: the model becomes an array and the panel stays open on pick.
maxLabelsnumbermultiple only: chips shown before the rest collapse into a "+N" chip.
display'text' | 'count' | 'chip''chip'multiple only: 'chip' shows chips, 'text' joined labels, 'count' "N selected".
disabledbooleanfalseDisables the trigger and keeps the panel from opening. A disabled parent Field also disables it.
clearablebooleanfalseShows a clear button in the trigger while a value is selected.
invalidbooleanfalseStandalone override; ORed with the nearest Field's error state.
size'sm' | 'md' | 'lg''md'Control size.
namestringRenders hidden inputs so a plain <form> post carries the selection.
side'top' | 'right' | 'bottom' | 'left''bottom'Which side of the trigger the panel opens on.
align'start' | 'end' | 'center''start'How the panel aligns against the trigger along that side.
sideOffsetnumber8Gap between the trigger and the panel, in pixels.
alignOffsetnumber0Shifts the panel along the alignment axis, in pixels.
panelWidthPanelWidthThe first level's width. Unset, it fits its rows and is at least as wide as the field, up to 16rem, so the next level opens close by. 'trigger' makes it at least the field's full width; a width in px or any CSS length ('20rem') sets it. The levels opening beside it keep their own width.
closeOnEscbooleantrueEscape key closes the panel.
closeOnOutsidebooleantrueClicking outside the panel closes it.
beforeCloseBeforeClose<PopoverCloseReason>Runs before the panel closes. Return true to close it, false to keep it open, or a promise of either, like () => confirmAction(…).result. The panel stays open while the promise is pending.
forceMountbooleanfalseKeeps it mounted while closed, toggled with v-show, so its content keeps its state. vael-ui then leaves its motion to you.
teleportTostring | HTMLElement'body'Teleport target: a CSS selector or element.
filterCascadeSelectFilter<T>Adds a search box to the panel. While you type, the levels become one list of the matching leaves, each with its path. true matches every word against the whole path, ignoring case and accents; a function matches your way; false leaves filtering to you via v-model:query.
filterPlaceholderstring'Search...'Placeholder for the search box.
scrollFadebooleantrueMasks the panel's top/bottom edge as its content scrolls under it, signaling there's more.
motionCascadeSelectMotiontrueHow it moves. false skips all of it: the menu opening and easing to its new height as you search, the clear button and the chips. An object moves the menu your way, like Menu's: values for the panel part, { spring }, or enter / leave hooks. chips does the same for the chips ({ chips: { initial: { chip: { opacity: 0, y: 4 } } } }).
uiPartial<Record<'trigger' | 'value' | 'positioner' | 'panel' | 'header' | 'filter' | 'footer' | 'start' | 'end' | 'clear' | 'chevron' | 'filterIcon', UiPartValue>>Class and style overrides for each part.
modelValueVnullSelected leaf value, or an array of leaf values with multiple.
openbooleanfalseWhether the panel is open.
querystring''Search box text. Clears when the panel closes.

Events

NameTypeDescription
open-change(value: boolean, details: PopoverOpenChangeDetails)Fires before the panel closes, with the reason; details.cancel() keeps it open.
select(item: T, path: CascadeSelectPath)Fires when a leaf is picked or unpicked, with the item and its root-to-leaf path.
change(value: V)Fires when you change the selection: picking a leaf, removing a chip, or clearing.
update:modelValue(value: V | undefined)Fires when modelValue changes (v-model).
update:open(value: boolean)Fires when open changes (v-model:open).
update:query(value: string)Fires when query changes (v-model:query).

Slots

NameTypeDescription
startanyContent at the start of the trigger, such as an icon, before the value.
endanyContent before the built-in clear button and chevron.
value{ selected: V extends unknown[] ? T[] : T | null; path: V extends unknown[] ? CascadeSelectPath[] : CascadeSelectPath; }Custom trigger content; receives the selected leaf and its path, or arrays of both.
headeranyContent above the row list, forwarded to the underlying Menu's #header.
item{ item: T; hasChildren: boolean; path: T[]; }Custom row content at any level; the row keeps its expand and select behavior. path is the items above it, so path.length is how deep it sits, even in search results.
emptyanyReplaces the localized "no options" row shown when items is empty.

Exposed

NameTypeDescription
elHTMLElement | nullRoot element.
triggerElHTMLElement | nullTrigger element: the frame around the button and its clear button. Focusing it focuses the button.
panelElHTMLElement | nullPanel element (null while closed).
positionerElHTMLElement | nullPositioning wrapper around the panel (null while closed).
listElHTMLElement | nullTop-level row list element (null while closed).
isClosingbooleantrue while a beforeClose close is pending.
selectedItemT | nullSelected leaf item, or null; always null with multiple.
selectedPathCascadeSelectPathRoot-to-leaf value path of the selection; empty when nothing is selected or with multiple.
open() => voidOpens the panel.
close() => voidCloses the panel, running @open-change and beforeClose first.
cancelClose() => voidCancels a close pending in beforeClose and keeps the panel open.

Motion New

CascadeSelect's menu, like Menu's. chips moves the chips; valueSwap: false shows a picked value without its crossfade.

<CascadeSelect
  :motion="{
    initial: { panel: { opacity: 0, y: 8, scale: 0.98 } },
    spring: { damping: 0.85, response: 0.35 },
  }"
/>
NameTypeDescription
initialexitpositionerpanelSets 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.
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.
morphlinkedexitOrder'trigger' | Record<string, LinkedMotion> | 'reverse'morph: 'trigger' grows it out of the element that opened it. linked moves other elements with it, such as the page receding behind it. exitOrder: 'reverse' closes its children first.
chipsChipsMotionA select's chips (multiple): values or hooks for chip, and the list's stagger and leaving.
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 Menu Button pattern from the WAI-ARIA Authoring Practices Guide.

KeyAction
ArrowDownArrowUpEnterSpaceOpens the menu from the trigger.
ArrowDownArrowUpMoves focus to the next or previous option in the level, wrapping at the ends.
HomeEndMoves focus to the first or last option in the level.
ArrowRightOpens the next level of a parent option and focuses its first option.
ArrowLeftCloses the current level and returns focus to its parent option.
EnterSpaceSelects the focused option, or opens the next level of a parent option.
A letterMoves focus to the next option whose label starts with the typed letters.
BackspaceDeleteRemoves the last chip from the focused trigger, with multiple.
EscapeCloses the innermost open level.
  • The trigger is a menu button: role="button" with aria-haspopup="menu", aria-expanded and aria-controls, read as its label followed by the value. Chip remove buttons inside it are pointer only, and the clear button is a Tab stop.
  • Each level is a role="menu" named by what opened it. Options are menuitems, or menuitemcheckboxes with aria-checked in multiple; parent options add aria-haspopup and aria-expanded. A single pick closes the menu; multiple keeps it open.
  • Focus moves into the menu on open, to the selected option’s path or the first option, and returns to the trigger on close or clear. With filter, focus starts in the search box: ArrowDown moves to the results, Enter picks the first one, and typing or Backspace on a result goes back to the search box.
  • Inside a Field, the label names the trigger. Without one, pass aria-label or aria-labelledby; the value is still read after it. Right to left, ArrowLeft and ArrowRight swap, and levels open to the left.