Every example is a complete Vue file. Copy it into an app that has the registry installed, or open it in StackBlitz. Type to filter; use the arrow keys and Enter.
In the page
Two groups with icons and shortcuts. Groups with no match hide; the empty message shows when nothing matches.
CommandInline.vue
<script setup lang="ts">
import { Boxes, PackageSearch, RefreshCw, Settings, Store, Users } from '@lucide/vue'
import {
Command,
CommandEmpty,
CommandGroup,
CommandInput,
CommandItem,
CommandList,
CommandSeparator,
CommandShortcut,
} from '@/components/ui/command'
</script>
<template>
<Command class="max-w-sm border-(length:--bh-border-width-default) border-(--bh-color-border)">
<CommandInput placeholder="Search pages and actions" />
<CommandList>
<CommandEmpty>Nothing matches.</CommandEmpty>
<CommandGroup heading="Go to">
<CommandItem value="orders"><PackageSearch />Orders</CommandItem>
<CommandItem value="products"><Boxes />Products</CommandItem>
<CommandItem value="customers"><Users />Customers</CommandItem>
</CommandGroup>
<CommandSeparator />
<CommandGroup heading="Actions">
<CommandItem value="sync"><RefreshCw />Sync now<CommandShortcut>Ctrl+R</CommandShortcut></CommandItem>
<CommandItem value="store"><Store />Connect an online store</CommandItem>
<CommandItem value="settings"><Settings />Settings<CommandShortcut>Ctrl+,</CommandShortcut></CommandItem>
</CommandGroup>
</CommandList>
</Command>
</template>Command palette
CommandDialog opened by a button or Ctrl + K. Its title and description are for screen readers.
CommandPalette.vue
<script setup lang="ts">
import { FileText, PackageSearch, RefreshCw, Store } from '@lucide/vue'
import { useMagicKeys, whenever } from '@vueuse/core'
import { ref } from 'vue'
import { Button } from '@/components/ui/button'
import {
CommandDialog,
CommandEmpty,
CommandGroup,
CommandInput,
CommandItem,
CommandList,
} from '@/components/ui/command'
const open = ref(false)
const { Ctrl_K, Meta_K } = useMagicKeys({
passive: false,
onEventFired(e) {
if (e.key === 'k' && (e.ctrlKey || e.metaKey) && e.type === 'keydown') e.preventDefault()
},
})
whenever(() => Ctrl_K.value || Meta_K.value, () => { open.value = true })
function run() {
open.value = false
}
</script>
<template>
<Button variant="outline" aria-keyshortcuts="Control+K" @click="open = true">Search (Ctrl+K)</Button>
<CommandDialog v-model:open="open" title="Search" description="Search for a page or an action to run.">
<CommandInput placeholder="Type a page, an order or an action" />
<CommandList>
<CommandEmpty>Nothing matches.</CommandEmpty>
<CommandGroup heading="Recent">
<CommandItem value="order-10482" @select="run"><PackageSearch />Order #10482</CommandItem>
<CommandItem value="invoice-2211" @select="run"><FileText />Invoice INV-2211</CommandItem>
</CommandGroup>
<CommandGroup heading="Actions">
<CommandItem value="sync-orders" @select="run"><RefreshCw />Sync orders to ERP</CommandItem>
<CommandItem value="connect-store" @select="run"><Store />Connect an online store</CommandItem>
</CommandGroup>
</CommandList>
</CommandDialog>
</template>