Summary
Add a Cmd+K / Ctrl+K command palette for search and quick actions — like Spotlight, VS Code, or Linear.
Usage
<!-- Layout (place once) -->
<StxCommandPalette placeholder="Search pages, actions...">
<template #empty>No results found</template>
</StxCommandPalette>
<script client>
// Register commands programmatically
commandPalette.register([
{ id: 'home', title: 'Go to Home', action: () => navigate('/') },
{ id: 'settings', title: 'Open Settings', action: () => modal.open('settings'), icon: 'settings' },
{ id: 'theme', title: 'Toggle Dark Mode', action: () => useDark().toggle() },
])
// Or auto-discover from navigation links
commandPalette.registerFromNav()
</script>API
<StxCommandPalette> props
placeholder— search input placeholder (default:'Search...')shortcut— keyboard shortcut (default:'meta+k')maxResults— max visible results (default:10)
commandPalette runtime global
commandPalette.open(): void
commandPalette.close(): void
commandPalette.register(commands: Command[]): void
commandPalette.registerFromNav(): void // auto-register from <a> links
interface Command {
id: string
title: string
description?: string
icon?: string
action: () => void
keywords?: string[] // extra search terms
group?: string // group header
}Implementation
- Builtin component rendering the overlay + search input
- Fuzzy search over registered commands
- Keyboard navigation (Arrow keys, Enter, Escape)
- Group headers for organized results
- Auto-register page links from navigation
- Focus trap, ARIA combobox pattern