Skip to content

CommandPalette ​

Search and run commands with the keyboard, opened with Ctrl + K (⌘ + K on Mac): navigation, actions, preferences.

Usage ​

Basic usage ​

Last command: —

vue
<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { Cog6ToothIcon, DocumentPlusIcon } from '@heroicons/vue/24/outline'

const router = useRouter()
const open = ref(false)
const commands = [
  { id: 'settings', label: 'Settings', group: 'Navigation', icon: Cog6ToothIcon,
    keywords: ['preferences', 'account'], onSelect: () => router.push('/settings') },
  { id: 'new', label: 'New document', group: 'Actions', icon: DocumentPlusIcon,
    shortcut: ['Ctrl', 'N'], onSelect: createDocument }
]
</script>

<template>
  <!-- Once in the application: Ctrl / ⌘ + K opens it -->
  <SuCommandPalette v-model:open="open" :commands="commands" />
</template>

The demo on this page disables the shortcut (:hotkey="false") so it does not interfere with the documentation search.

API ​

Props ​

PropTypeDefaultDescription
openbooleanfalseOpen state (v-model:open)
commandsCommandItem[][]Commands
placeholderstring'Search for a command…' (locale)Field placeholder
hotkeystring | false'k'Shortcut key with Ctrl / ⌘; false: none
emptyTextstring'No results' (locale)Text without results
ariaLabelstring'Command palette' (locale)Dialog and list name

CommandItem ​

PropertyTypeDescription
idstringIdentifier
labelstringLabel
groupstringDisplay group
descriptionstringSecondary text (also searched)
iconComponentIcon
shortcutstring[]Displayed shortcut (SuKbd)
keywordsstring[]Extra search terms
disabledbooleanUnavailable command
onSelect() => voidAction, called after closing

Events ​

EventPayloadDescription
update:openbooleanOpened or closed
selectCommandItemCommand run

Accessibility ​

  • Native modal SuDialog named "Command palette"; focus goes to the search field and returns to the trigger when closing.
  • role="combobox" field linked to a role="listbox" list whose groups (role="group") are named.
  • Focus stays in the field: ↑ / ↓ browse results (aria-activedescendant, unavailable commands skipped), Enter runs, Escape closes.
  • Accent- and case-insensitive search; results ranked (label start, label, then description and keywords). The number of results is announced.

Publié sous licence MIT.