vael-ui v0.5.7

Selection

Layout

Select

A dropdown for picking one or more values from a list, with filtering and virtualization. Use it when a list is too long for radios or a SelectButton.

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

Install

import { Select } from 'vael-ui'

Playground

Placement, behaviour and animation

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

const items = [
  { label: 'Apple', value: 'apple' },
  { label: 'Banana', value: 'banana' },
  { label: 'Cherry', value: 'cherry' },
]
const value = ref<string | number | (string | number)[] | null>(null)
const open = ref(false)
</script>

<template>
  <Select
    placeholder="Choose an option"
    aria-label="Fruits"
    :items="items"
    v-model="value"
    v-model:open="open"
  />
</template>

Props

NameTypeDefaultDescription
itemsRequiredreadonly (T | SelectGroupData<T>)[]Options to choose from. Put { label, items } entries among them to show options under a group label, like <optgroup>.
placeholderstringText shown in the trigger while nothing is selected.
multiplebooleanfalseLets you select several items. The model becomes an array and the panel stays open on pick.
disabledbooleanfalseDisables the trigger and blocks interaction.
invalidbooleanfalseMarks the field invalid. ORed with the nearest Field's error state.
size'sm' | 'md' | 'lg''md'Trigger size.
loadingbooleanfalseShows a spinner in place of an empty list, or below the rows while more load.
clearablebooleanfalseShows a clear button once something is selected.
maxLabelsnumbermultiple only: how many chips show before the rest collapse into a "+N" chip. Unset, all show.
display'text' | 'count' | 'chip''chip'multiple only: 'chip' shows removable chips, 'text' comma-joined labels, 'count' an "N selected" summary.
virtualizeboolean | SelectVirtualizeConfigtrue/false forces virtualization on/off; an object also tunes itemSize/overscan. Unset, it auto-virtualizes past 100 items.
namestringRenders hidden <input>(s) so a plain <form> post carries the selection, repeating name when multiple.
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.
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.
scrollFadebooleantrueMasks the panel's top/bottom edge as its content scrolls under it, signaling there's more.
maxPanelHeightnumber320Caps the panel height in pixels; the list scrolls past it. The viewport limits it too, so pass Infinity to fill the available space.
panelWidthPanelWidth'trigger'The panel's width. 'trigger' matches the field (at least 12rem); a width in px or any CSS length ('20rem') sets it.
motionSelectMotiontrueHow it moves. false skips all of it: the panel opening, the list easing to its new height as you search, the clear button and the chips. An object moves the panel your way, like Popover'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 } } } }).
filterSelectFilter<T>Adds a search box to the panel. true matches labels 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.
uiPartial<Record<'trigger' | 'value' | 'positioner' | 'panel' | 'header' | 'filter' | 'list' | 'option' | 'group' | 'groupLabel' | 'empty' | 'footer' | 'start' | 'end' | 'clear' | 'chevron' | 'filterIcon', UiPartValue>>Class and style overrides for each part.
modelValuestring | number | (string | number)[] | nullnullSelected value, or an array of values when multiple.
querystring''Search box text. Clears when the panel closes.
openbooleanfalseWhether the panel is open.

Events

NameTypeDescription
open-change(value: boolean, details: PopoverOpenChangeDetails)Fires before the panel closes; details.cancel() keeps it open.
select(item: T)Fires when you pick an item, including a pick that deselects it in multiple mode.
change(value: string | number | (string | number)[] | null)Fires when you change the selection, including chip removal and clear.
reach-end()Fires when the list's last rows render, for loading more. Re-arms when the item count changes.
update:modelValue(value: string | number | (string | number)[] | null)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: T | T[] | null; }Custom trigger content for the current selection (an array when multiple). It replaces the built-in label and its crossfade; to keep the crossfade, put the text in <AnimatedText :value="…" />.
header{ count: number; total: number; }Content above the filter input (when filter is on) or the listbox. count and total support a result-count readout.
filter{ query: string; onKeydown: (event: KeyboardEvent) => void; }Replaces the built-in filter row. Bind your input to v-model:query; pass keys to onKeydown to keep arrow/Home/End/Enter list navigation.
filter-iconanyReplaces only the built-in filter row's leading icon and keeps its Input frame.
item{ item: T; index: number; active: boolean; selected: boolean; group?: SelectGroupSlotData<T> | undefined; }Custom row content for each option. group is the group it sits in, if any.
group-label{ group: SelectGroupSlotData<T>; items: T[]; }Custom content for a group's label. group is the object you passed, with your own fields; items are its options still showing. Screen readers read this content as the group's name.
emptyanyReplaces the text shown when no items match.

Exposed

NameTypeDescription
elHTMLElement | nullRoot element: the trigger frame.
triggerElHTMLElement | nullTrigger element: the frame around the combobox and its clear button. Focusing it focuses the combobox.
panelElHTMLElement | nullPanel element (null while closed).
positionerElHTMLElement | nullPositioning wrapper around the panel (null while closed).
listElHTMLElement | nullScrollable listbox element (null while closed).
highlightElHTMLElement | nullThe hover and keyboard highlight, sliding between options (null while closed). With motion: false it moves at once, for your own animation.
filterInputRef{ el: HTMLElement | null; inputEl: HTMLInputElement | null; } | nullBuilt-in search Input instance (null without filter, with a #filter slot, or while closed).
placementPlacementResolved placement after flipping, e.g. 'bottom-start'.
positionerStyleRecord<string, string>Inline positioning styles applied to the positioner.
isClosingbooleanTrue while a beforeClose close is pending.
open() => voidOpens the panel (no-op while disabled).
close() => voidCloses the panel, running @open-change and beforeClose first.
cancelClose() => voidCancels a close pending in beforeClose and keeps the panel open.
activeIndexnumberIndex of the highlighted row in the filtered list (-1 for none).
scrollToIndex(index: number, align?: ScrollAlign | undefined) => voidScrolls the list to the row at index.

Motion New

Select's panel: values or hooks for its parts, like Popover's. chips moves the chips; valueSwap: false shows a picked value without its crossfade.

<Select
  :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 Combobox pattern from the WAI-ARIA Authoring Practices Guide.

KeyAction
ArrowDownArrowUpEnterSpaceOpens the list when it’s closed.
ArrowDownArrowUpMoves the highlight to the next or previous option, wrapping at the ends.
HomeEndMoves the highlight to the first or last option.
EnterSpaceSelects the highlighted option, or toggles it with multiple.
A letterMoves the highlight to the next option whose label starts with the typed letters.
BackspaceDeleteRemoves the last chip, with multiple.
EscapeCloses the list and puts focus on the trigger.
TabCloses the list and moves focus on.
  • The trigger has role="combobox" with aria-haspopup="listbox", aria-expanded and aria-controls. Options have role="option" and aria-selected; multiple adds aria-multiselectable, and a virtualized list adds aria-setsize and aria-posinset. Groups render as role="group", named by their label.
  • Focus stays on the trigger, and aria-activedescendant points at the highlighted option, starting on the selected one. With filter, focus moves to the search box, which becomes the combobox; Space types a space there.
  • A single select closes when you pick; multiple stays open. Chip remove buttons are pointer only. The clear button is a Tab stop, and clearing puts focus back on the trigger.
  • Inside a Field, the label names the trigger. Without one, pass aria-label or aria-labelledby.