StealThis .dev

Command Palette (⌘K)

A keyboard-driven command palette modal triggered by ⌘K / Ctrl+K, with fuzzy search, keyboard navigation, and smooth open/close animation.

Open in Lab
vanilla-js css keyboard-events
Targets: JS HTML

Code

Command Palette (⌘K)

A fully accessible command palette modal triggered by ⌘K (Mac) or Ctrl+K (Windows/Linux). Features real-time fuzzy search, full keyboard navigation, and smooth enter/exit animations.

How it works

  1. keydown listener catches ⌘K / Ctrl+K and toggles the overlay
  2. The search <input> filters commands in real-time using includes() matching
  3. Arrow keys move the active index; Enter executes the highlighted command
  4. Clicking the backdrop or pressing Escape closes the palette

Accessibility

  • role="dialog" + aria-modal="true" on the overlay
  • aria-label on the search input
  • Focus is trapped inside the modal while open
  • prefers-reduced-motion respected for animations

When to use it

  • App-wide navigation shortcut
  • Quick action launcher
  • Developer tools / power-user features