Skip to content

CommandPalette ​

CommandPalette is a keyboard-first command launcher built on the Dialog. Open it, type to filter a flat list of commands, and pick one with the mouse or the keyboard (↓/↑ to move, Enter to run, Esc to close).

vue
<script setup lang="ts">
import { ref } from 'vue'
import { CommandPalette, type CommandItem } from '@myghf/ui'

const open = ref(false)
const items: CommandItem[] = [
  { id: 'new-patient', label: 'New patient', group: 'Patients' },
  { id: 'settings', label: 'Settings', group: 'App' },
]
</script>

<template>
  <CommandPalette v-model:open="open" :items="items" @select="(item) => run(item.id)" />
</template>

No command run yet

vue
<script setup lang="ts">
import { ref } from 'vue'
import { Button, CommandPalette, type CommandItem } from '@myghf/ui'

const open = ref(false)
const selected = ref('')

const items: CommandItem[] = [
  { id: 'new-patient', label: 'New patient', description: 'Register an admission', group: 'Patients', icon: 'plus' },
  { id: 'new-appointment', label: 'New appointment', description: 'Schedule a visit', group: 'Patients', icon: 'calendar' },
  { id: 'settings', label: 'Settings', group: 'App', icon: 'settings' },
]

function onSelect(item: CommandItem) {
  selected.value = item.label
}
</script>

<template>
  <div class="grid gap-2">
    <div>
      <Button size="sm" @click="open = true">Open command palette</Button>
    </div>
    <p class="text-sm text-muted">
      {{ selected ? `Last command: ${selected}` : 'No command run yet' }}
    </p>
    <CommandPalette v-model:open="open" :items="items" @select="onSelect" />
  </div>
</template>

Props ​

PropTypeDefaultDescription
openbooleanfalseOpen state. Bind with v-model:open.
itemsCommandItem[][]The commands to search.
placeholderstring'Type a command…'Search input placeholder.
emptyLabelstring'No results'Shown when nothing matches.
searchLabelstring'Search commands'Accessible name for the search input.
titlestring'Command palette'Screen-reader-only dialog title.
descriptionstring'Search for and run a command.'Screen-reader-only dialog description.

CommandItem ​

ts
interface CommandItem {
  id: string
  label: string
  description?: string
  group?: string       // short trailing label, e.g. a section name
  keywords?: string[]  // extra terms to match against
  icon?: string        // Lucide icon name
}

Events ​

EventPayloadDescription
update:openbooleanEmitted when the palette opens or closes.
selectCommandItemEmitted with the chosen command; the palette then closes.

Accessibility ​

  • The palette is a labelled dialog (a visually-hidden title and description), so it announces its purpose on open. Focus moves to the search input when it opens.
  • Results are real <button>s in a list, so they are keyboard reachable; ↓/↑ from the input move focus into the list, and Esc closes the dialog and returns focus to whatever opened it.
  • Filtering matches the label, description, and any keywords, so results stay reachable by typing alone.

Dark mode & RTL ​

  • The panel uses semantic tokens (bg-surface, border-border, shadow-dialog), so it adapts to dark mode automatically. Layout is logical (text-start, gap), so it mirrors correctly under dir="rtl".

Released under the MIT License.