Skip to Content
TelamonJS

CommandPalette

Keyboard-driven command palette (Cmd+K) for quick navigation and actions

Keyboard-driven command palette (Cmd+K) for quick navigation, search, and actions inspired by VS Code and Linear. Built on cmdk.

Power User Tool

CommandPalette dramatically improves navigation speed - users can access any page or action with just a few keystrokes. It is part of the canonical app shell (see AdminShell).


Basic Usage

'use client'

import { CommandPalette, type CommandPaletteItem } from '@telamonjs/ui'
import { Home, Users } from 'lucide-react'
import { useRouter } from 'next/navigation'

export default function AppCommandPalette() {
  const router = useRouter()

  const items: CommandPaletteItem[] = [
    {
      id: 'dashboard',
      label: 'Go to Dashboard',
      type: 'navigation',
      icon: Home,
      href: '/admin',
      keywords: ['home', 'overview'],
    },
    {
      id: 'users',
      label: 'Go to Users',
      type: 'navigation',
      icon: Users,
      href: '/admin/users',
      keywords: ['people', 'accounts'],
    },
  ]

  return (
    <CommandPalette
      items={items}
      onSelect={item => item.href && router.push(item.href)}
    />
  )
}

Press Cmd+K (Mac) or Ctrl+K (Windows/Linux) to open (enabled by default).

The prop is `items`, and navigation is yours

CommandPalette uses items: CommandPaletteItem[]: grouping comes from the item's type, the per-item callback is onSelect, and href is data — wire navigation in the component-level onSelect (e.g. router.push). There is no built-in recent-commands storage; feed type: 'recent' items yourself if you want that group.


Props

Prop

Type

CommandPaletteItem

Prop

Type


Examples

With Actions

import { Plus, Download } from 'lucide-react'

const items: CommandPaletteItem[] = [
  {
    id: 'new-user',
    label: 'Create New User',
    type: 'action',
    icon: Plus,
    shortcut: '⌘N',
    onSelect: () => openCreateUserDialog(),
  },
  {
    id: 'export',
    label: 'Export Data',
    type: 'action',
    icon: Download,
    onSelect: () => openExportDialog(),
  },
]

<CommandPalette items={items} />

Controlled

'use client'

import { useState } from 'react'
import {
  CommandPalette,
  Button,
  type CommandPaletteItem,
} from '@telamonjs/ui'

export function Toolbar({ items }: { items: CommandPaletteItem[] }) {
  const [open, setOpen] = useState(false)

  return (
    <>
      <Button variant='outline' onClick={() => setOpen(true)}>
        Search... <kbd className='ml-2 text-xs'>⌘K</kbd>
      </Button>

      <CommandPalette
        items={items}
        open={open}
        onOpenChange={setOpen}
      />
    </>
  )
}

Custom Shortcut

<CommandPalette items={items} shortcutKey='p' />  {/* Cmd/Ctrl+P */}
<CommandPalette items={items} enableShortcut={false} />  {/* controlled only */}

The shortcut always combines shortcutKey with Cmd/Ctrl — a bare / trigger is not supported.


Complete Example

components/app-command-palette.tsx
'use client'

import { CommandPalette, type CommandPaletteItem } from '@telamonjs/ui'
import { Home, Users, Package, Plus, Moon, Sun } from 'lucide-react'
import { useRouter } from 'next/navigation'
import { useTheme } from 'next-themes'

export default function AppCommandPalette() {
  const router = useRouter()
  const { setTheme } = useTheme()

  const items: CommandPaletteItem[] = [
    // Navigation group
    { id: 'nav-dashboard', label: 'Go to Dashboard', type: 'navigation', icon: Home, href: '/admin', keywords: ['home'] },
    { id: 'nav-users', label: 'Go to Users', type: 'navigation', icon: Users, href: '/admin/users', keywords: ['people', 'accounts'] },
    { id: 'nav-products', label: 'Go to Products', type: 'navigation', icon: Package, href: '/admin/products' },

    // Actions group
    { id: 'action-new-user', label: 'Create New User', type: 'action', icon: Plus, shortcut: '⌘N', href: '/admin/users/new' },
    { id: 'theme-light', label: 'Switch to Light Theme', type: 'action', icon: Sun, onSelect: () => setTheme('light') },
    { id: 'theme-dark', label: 'Switch to Dark Theme', type: 'action', icon: Moon, onSelect: () => setTheme('dark') },
  ]

  return (
    <CommandPalette
      items={items}
      placeholder='Type a command or search...'
      onSelect={item => item.href && router.push(item.href)}
    />
  )
}

Search & Filtering

Filtering comes from cmdk (accent-insensitive) — type to filter across labels, with keywords adding extra matchable terms per item:

{
  label: 'Go to Users',
  keywords: ['people', 'accounts', 'customers'],
  // Also matches: "people", "accounts", "customers"
}

Use Cases

  • Quick navigation - Jump to any page instantly
  • Actions - Execute common operations
  • Settings - Toggle themes, preferences
  • Admin tools - Debug, clear cache, etc.

Best Practices

  1. Add all pages - Every major page should have a navigation item
  2. Use keywords - Add search aliases for better discovery
  3. Group by type - navigation / action / search / recent drive the section headings
  4. Clear labels - Use action-oriented labels ("Go to...", "Create...")
  5. Add icons - Improve visual scanning
  6. Limit items - 50-100 max; filtering is client-side and instant

Keyboard Shortcuts

  • Cmd+K / Ctrl+K - Toggle palette (configurable via shortcutKey)
  • ↓ / ↑ - Move selection
  • Enter - Execute selected item
  • Esc - Close palette

Accessibility

  • Keyboard-only operation (cmdk + Radix Dialog)
  • Focus trapped in the dialog while open
  • shortcut text renders as a <kbd> hint next to the item


See Also


Status: ✅ Stable

On this page