Configs2026年5月29日·1 分钟阅读

KBar — Fast Command Palette Interface for React

A portable, extensible command+k interface for React applications that provides fuzzy search, keyboard navigation, and nested action support.

Agent 就绪

Agent 可直接安装

这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
KBar Overview
直接安装命令
npx -y tokrepo@latest install 4621ed21-5af4-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run 确认安装计划,再运行此命令。

Introduction

KBar adds a command palette (Cmd+K or Ctrl+K) to React applications, similar to the interfaces found in VS Code, Slack, and Linear. It provides a composable set of React components for the search input, results list, and positioning, along with a data-driven action system that supports keyboard shortcuts, nested sub-actions, and dynamic action registration.

What KBar Does

  • Provides a Cmd+K / Ctrl+K triggered command palette overlay
  • Fuzzy-searches registered actions by name and keywords in real time
  • Supports nested actions for hierarchical navigation (e.g., Settings > Theme > Dark)
  • Allows dynamic action registration and removal at runtime
  • Handles keyboard navigation with arrow keys, Enter, and Escape

Architecture Overview

KBar uses a React context provider (KBarProvider) to manage a store of actions and UI state (open, search query, active action path). The search component dispatches query updates to the store, which filters actions using a built-in fuzzy matching algorithm. Results are rendered via a virtualized list component for performance with large action sets. The portal, positioner, and animator components handle overlay placement and enter/exit transitions. Actions can be static (defined at provider mount) or dynamic (registered by child components via useRegisterActions).

Installation & Configuration

  • Install via npm: npm install kbar
  • Wrap your app in KBarProvider with an actions array
  • Compose KBarPortal, KBarPositioner, KBarAnimator, KBarSearch, and KBarResults inside the provider
  • Define actions with id, name, optional shortcut, and a perform callback
  • Use useRegisterActions to add context-specific actions from nested components

Key Features

  • Composable architecture with separate components for each UI concern
  • Dynamic action registration from any component in the tree
  • Nested actions for multi-level navigation menus
  • Built-in keyboard shortcut binding for individual actions
  • Fully stylable via className props on each component

Comparison with Similar Tools

  • cmdk — Pacocoursey command menu with opinionated styling; less composable architecture
  • ninja-keys — web component based; framework-agnostic but less React-idiomatic
  • react-command-palette — older library with fewer features and less active development
  • Spotlight (Mantine) — tied to the Mantine UI ecosystem
  • VS Code command palette — inspiration for KBar; not a reusable library

FAQ

Q: How do I trigger the palette with a custom keyboard shortcut? A: KBar opens on Cmd+K by default. You can customize the toggle shortcut by passing a custom toggle action or handling it via the useKBar hook.

Q: Can I add actions dynamically based on the current page? A: Yes. Use the useRegisterActions hook in any component to register and unregister actions tied to that component's lifecycle.

Q: Does KBar support sections or groups in the results? A: Yes. Actions with a section property are grouped under section headers in the results list.

Q: How do I style the command palette? A: Each component (KBarAnimator, KBarSearch, KBarResults) accepts style and className props for custom CSS.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产