ReviewOS

stacks/stx

Built-in Command Palette (<StxCommandPalette />)

#1675
Closed glennmichael123 opened this 23 days ago · 1 comment
23 days ago

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
23 days ago

Delivered via @stacksjs/components, which ships with every stx app and is auto-registered (no import needed in .stx files). See CLAUDE.md § "Reach for stx primitives before vanilla JS" for the full inventory; the relevant components for this request are documented there.

Closing as effectively delivered. If a specific behavior or API affordance from the original request is missing from the shipped components, please open a focused ticket against @stacksjs/components describing the exact gap — that's easier to track than a broad "make it a builtin" ask.

Sign in to comment on this issue.