Command palette
VCommandPalette opens a search field over a list of commands in a native modal dialog. Type to narrow the list, use the arrows to move and Enter to run a command. The shortcut prop opens it from anywhere in the page.
Usage
Examples
Groups
Pass commands, named groups and separators in items. keywords are matched without being shown, and the shortcut of a command is displayed only.
Links
A command with href is a link: Enter follows it, and a modified click opens it in a new tab. With a router, call event.preventDefault() in select and navigate yourself.
Asynchronous search
Set filter to false and load the commands on search, which is debounced. loading shows a spinner in the field.
Recent commands
The palette keeps no history. Record choices from select and add a group of recent commands while v-model:query is empty.
API
Props
| Prop | Type | Default |
|---|---|---|
items | CommandPaletteItem[] | none |
| Commands, named groups and separators. | ||
shortcut | string | none |
Page-wide shortcut that toggles the palette, such as mod+k. Ignored while typing in another field. Adds aria-keyshortcuts to the trigger. | ||
filter | CommandPaletteFilter | true |
| Built-in accent-insensitive filtering on labels and keywords, disabled filtering, or a custom function receiving the command and trimmed query. | ||
searchDebounce | number | 250 |
| Delay in milliseconds before emitting a typed search. Zero emits immediately. | ||
loading | boolean | false |
| Shows a field spinner, and a loading row while no command is available. | ||
loadingText | string | none |
Loading text announced to screen readers. Keep it consistent with custom #loading content. | ||
emptyText | string | none |
Title of the default VEmptyState, also announced to screen readers. Keep it consistent with custom #empty content. | ||
placeholder | string | none |
| Placeholder of the search field. Defaults to the library dictionary. | ||
label | string | none |
| Accessible name of the palette and its list. Defaults to the library dictionary. | ||
searchLabel | string | none |
| Accessible name of the search field. Defaults to the library dictionary. | ||
hideFooter | boolean | false |
| Hides the footer listing the keys. | ||
width | number | string | none |
| Palette width: pixels for numbers, otherwise a CSS length. | ||
v-model:open | boolean | false |
| Palette open state. Native dismissal updates the model. | ||
v-model:query | string | '' |
| Search text. Emptied when the palette closes. | ||
Events
| Event | Type |
|---|---|
search | [query: string] |
Emits the search term after searchDebounce, or immediately on opening. Consecutive duplicate terms are skipped. | |
select | [command: CommandPaletteCommand, event: MouseEvent] |
Emitted with the command and the click event when a command is chosen. The palette then closes unless the command has keepOpen. | |
Slots
| Slot | Type |
|---|---|
trigger | { triggerProps: CommandPaletteTriggerProps; } |
Opening control. Bind the supplied triggerProps. | |
item | CommandPaletteItemSlotProps |
| Label and description of a row. Receives the command and its active state. | |
empty | CommandPaletteEmptySlotProps |
Empty-state content. Receives the search query; also set emptyText. | |
loading | {} |
Loading content. Also set loadingText. | |
footer | {} |
| Replaces the footer listing the keys. | |
Types
Types used in the API tables. Import exported types from vectis-ui.
export interface BuiltinIcon {
name: string
paths: readonly [string] | readonly [string, string]
}export interface CommandPaletteCommand {
label: string
description?: string
keywords?: string[]
icon?: IconSource
shortcut?: string
href?: string
disabled?: boolean
keepOpen?: boolean
id?: string | number
}export interface CommandPaletteEmptySlotProps {
query: string
}export type CommandPaletteFilter = boolean | ((command: CommandPaletteCommand, query: string) => boolean)
export interface CommandPaletteGroup {
label: string
commands: CommandPaletteCommand[]
}export type CommandPaletteItem = CommandPaletteCommand | CommandPaletteGroup | CommandPaletteSeparator
export interface CommandPaletteItemSlotProps {
command: CommandPaletteCommand
active: boolean
}export interface CommandPaletteSeparator {
separator: true
}export type CommandPaletteTriggerProps = {
onClick: () => void
'aria-haspopup': 'dialog'
'aria-keyshortcuts'?: string
}export type IconRender =
| { path: string; viewBox?: string }
| { component: Component; props?: Record<string, unknown> }
| { src: string }
| { text: string; class?: string }
| { class: string }export type IconSource = string | BuiltinIcon | IconRender
CSS variables
| Token | Value |
|---|---|
--vectis-control-size-command-palette-width | 40rem |
--vectis-control-size-command-palette-list-max-block | 20rem |
--vectis-control-size-command-palette-offset | 6rem |