agentworkforce avatar

Implementing Command Palettes

This covers the mechanical details of building Cmd+K command palettes in React without the infinite re-render headaches. It walks through the wrapper component pattern to prevent keyboard listeners firing when closed, arrow key navigation that clamps indices properly, scrollIntoView with block nearest to avoid jarring jumps, and the crucial bit about defining icon elements outside your component so they don't break reference equality. The shortcut matching strips spaces so "gd" finds "g d" commands. If you've fought with a command palette that feels laggy or re-renders constantly when filtering, the stable references section explains exactly why that happens and how to fix it.

GitHub stars
719
last updated
Jun 11, 2026

Install

$ npx -y skills add agentworkforce/relay --skill implementing-command-palettes --agent claude-code

Installs into .claude/skills of the current project.

Files

Implementing Command Palettes

Overview

Command palettes (Cmd+K / Ctrl+K) need precise keyboard navigation, scroll behavior, and stable references to avoid re-render loops. This skill covers the mechanical patterns that make command palettes feel responsive.

When to Use

  • Building a Cmd+K command palette in React
  • Implementing arrow key navigation with visual selection
  • Keeping selected items visible during keyboard navigation
  • Filtering commands by label text AND keyboard shortcuts
  • Experiencing infinite re-renders when commands update

Quick Reference

FeatureImplementation
Arrow navigationTrack selectedIndex, clamp with Math.min/max
Keep in viewscrollIntoView({ block: 'nearest', behavior: 'smooth' })
Shortcut matchingStrip spaces from shortcuts, match against query
Stable iconsDefine icon elements outside component
Stable handlersuseCallback + noop constant for disabled states

Keyboard Navigation

Sponsors

Details

Repository
github.com/agentworkforce/relay
Category
Frontend Development
License
Apache-2.0
First seen
Jun 11, 2026

More from agentworkforce/relay

All 18
1agnosticui avatarcheck-accessibilityagnosticui/agnosticuiReview component for accessibility issues0skills.sh installs
2agnosticui avatarimplement-ag-playbookagnosticui/agnosticuiImplement a playbook from its PROMPT specification files. Supports both single-framework (PROMPT-REACT.md, etc.) and 3-framework (PROMPT-3-FRAMEWORKS.md) modes.0skills.sh installs
3agnosticui avatarimplement-github-featureagnosticui/agnosticuiDesign and implement a new feature or component from a GitHub issue. Use for net-new functionality, not bug fixes.0skills.sh installs
4cloudposse avatardocs-stylescloudposse/docsCSS styles, color themes, and visual conventions for docs.cloudposse.com. Use when styling components, mermaid diagrams, or working with site theming.0skills.sh installs
5daffy0208 avatardesign-system-architectdaffy0208/ai-dev-standardsBuild scalable, maintainable design systems that unify product experiences. Use when creating component libraries, design tokens, or establishing design standar0skills.sh installs
6erichowens avatarproduct-appeal-analyzererichowens/some_claude_skillsEvaluate product desirability, market positioning, and emotional resonance—the complement to friction analysis. Assess whether users will WANT a product (not ju0skills.sh installs