vael-ui v0.5.7

Overlays

Layout

CommandPalette

A searchable list of commands in a dialog, opened from a button or a keyboard shortcut such as ⌘K. Use it to let people reach any action or page from the keyboard.

Install

import { CommandPalette } from 'vael-ui'

Playground

Placement, behaviour and animation

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

const items = [
  { id: 'new-file', label: 'New File', description: 'Create a blank document' },
  { id: 'new-folder', label: 'New Folder', description: 'Group related files' },
  {
    id: 'open-settings',
    label: 'Open Settings',
    description: 'Preferences and theme',
  },
]
const open = ref(false)
</script>

<template>
  <CommandPalette
    placeholder="Type here…"
    :items="items"
    v-model:open="open"
  />
</template>

Props

NameTypeDefaultDescription
itemsRequiredreadonly T[]Commands to search and run.
placeholderstringSearch input placeholder. Falls back to the localized message.
filter((item: T, query: string) => boolean)Custom filter function; replaces the default label/keywords match. Omit to use the built-in filter.
shortcutstringGlobal shortcut that toggles open, such as 'mod+k' (mod is Cmd on Mac, Ctrl elsewhere). Nothing listens until you set it.
closeOnSelectbooleantrueCloses the palette after an item is selected.
loadingbooleanfalseResults are on their way (a server search): shows a spinner instead of "No results" while the list is empty.
size'sm' | 'md' | 'lg''lg'Panel width, as in Dialog.
position'top' | 'right' | 'bottom' | 'left' | 'center''top'Where the panel anchors in the viewport. 'top' matches the Spotlight/Raycast convention; 'center' feels more like a Dialog.
modalbooleantruefalse turns off the overlay, scroll lock, focus trap and the inert page behind it. Escape-to-close and layer stacking still apply.
closeOnEscbooleantrueEscape key closes the panel.
closeOnOverlaybooleantrueClicking the overlay closes the panel. Has no effect when modal is false, since there's no overlay.
beforeCloseBeforeClose<DialogCloseReason>Runs before the palette closes. Return true to close it, false to keep it open, or a promise of either, like () => confirmAction(…).result. The palette stays open while the promise is pending. CommandPalette passes it to its Dialog.
forceMountbooleanfalseKeeps it mounted while closed, toggled with v-show, so its content keeps its state. vael-ui then leaves its motion to you. Forwarded to the underlying Dialog.
motionCommandPaletteMotiontrueHow it moves. false skips all of it: opening, closing, and the results easing to their new height as you type (rows change at once). An object moves the dialog your way, like Dialog's: values for its parts, { spring }, or enter / leave hooks. items animates the rows ({ items: { initial: { item: { opacity: 0 } } } }).
teleportTostringTeleport target: a CSS selector. Takes precedence over container.
containerDOMTargetScopes the palette to one element instead of the viewport. Forwarded to the underlying Dialog.
scrollTargetDOMTargetElement whose scrolling locks while the palette is open, if different from container. Forwarded to the underlying Dialog.
uiPartial<Record<'panel' | 'input' | 'list' | 'groupLabel' | 'item' | 'empty' | 'footer' | 'icon', UiPartValue>>Class and style overrides for each part.
openbooleanfalseWhether the palette is open.
querystring''Search text. Resets to empty each time the palette opens.

Events

NameTypeDescription
open-change(value: boolean, details: DialogOpenChangeDetails)Fires before the palette closes, with the reason; details.cancel() keeps it open.
select(item: T)Fires when you pick an enabled item by click or Enter.
update:open(value: boolean)Fires when open changes (v-model:open).
update:query(value: string)Fires when query changes (v-model:query).

Slots

NameTypeDescription
item{ item: T; index: number; active: boolean; group: string | undefined; select: () => void; }Custom row content for each item; call select() to pick it. group is its group's name.
group-label{ group: string; items: T[]; }Custom content for a group's heading. group is its name; items are its items still showing.
emptyanyReplaces the localized "no results" row shown when nothing matches.
loadinganyReplaces the spinner shown while loading and the list is empty.

Exposed

NameTypeDescription
panelElHTMLElement | nullPanel element (null while closed).
isClosingbooleantrue while a beforeClose close is pending.
close() => voidCloses the palette, running @open-change and beforeClose first.
cancelClose() => voidCancels a close pending in beforeClose and keeps the palette open.
inputElHTMLInputElement | nullSearch input element (null while closed).
listElHTMLElement | nullResults list element (null while closed).
highlightElHTMLElement | nullThe hover and keyboard highlight, sliding between items (null while closed). With motion: false it moves at once, for your own animation.
filteredItemsT[]Items matching the current query, in items order.
activeIndexnumberIndex of the highlighted item in filteredItems (-1 when none).
activeItemTThe highlighted item, for acting on it from your own keys (copy, open in a new tab).

Motion New

CommandPalette's dialog, like Dialog's. items moves the result rows.

<CommandPalette
  :motion="{
    initial: { panel: { opacity: 0, y: 8, scale: 0.98 } },
    spring: { damping: 0.85, response: 0.35 },
  }"
/>
NameTypeDescription
initialexitoverlaypanelheadertitledescriptionbodyfootermaximizecloseSets 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.
swapresize'sync' | 'wait' | booleanContent that changes while it's open crossfades ('sync') or waits for the old view to leave ('wait'), and the box eases to its new size unless resize: false.
itemsCommandPaletteItemsMotionThe result rows: values or hooks for item, and the list's stagger.
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
ArrowDownArrowUpHighlights the next or previous enabled item, wrapping at the ends.
EnterSelects the highlighted item and closes the palette, unless closeOnSelect is false.
EscapeCloses the palette, unless closeOnEsc is false.
TabShiftTabMoves focus within the palette, wrapping at the ends.
  • A modal Dialog, so the rest of the page is inert. A translated “Command palette” label names both the dialog and the search input. Focus goes to the input on open and returns to the opener on close.
  • The input has role="combobox" and aria-controls pointing at a role="listbox". Items are role="option" with aria-selected, and aria-disabled when disabled. Groups are role="group", named by their headings.
  • Focus stays in the input; aria-activedescendant points at the highlighted item. As you type, a role="status" region announces the number of results, or that there are none.
  • shortcut, such as "mod+k", toggles the palette from anywhere on the page.