Command Palette
Beautiful, accessible command palette for the web. Fuzzy search, keyboard navigation, nested commands, and full ARIA support — all in ~6KB with zero dependencies.
Features
Everything you need for a world-class command palette experience.
Installation
Install via npm or use directly from CDN.
npm / yarn / pnpm
npm install @bw-ui/command-palette
CDN
<link rel="stylesheet" href="https://unpkg.com/@bw-ui/command-palette/dist/bw-command-palette.min.css"> <script src="https://unpkg.com/@bw-ui/command-palette/dist/bw-command-palette.min.js"></script>
Quick Start
Get up and running in under a minute.
import { BWCommandPalette } from '@bw-ui/command-palette'; const cmd = new BWCommandPalette({ trigger: 'mod+k', commands: [ { id: 'new-file', label: 'New File', icon: '📄', action: () => createFile() }, { id: 'settings', label: 'Settings', icon: '⚙️', children: [...] }, ], });
The mod key is ⌘ on Mac and
Ctrl on Windows/Linux.
Options
Configuration options for the command palette.
| Option | Type | Default | Description |
|---|---|---|---|
trigger |
string | false |
'mod+k' |
Hotkey to open |
commands |
Command[] | Function |
[] |
Commands array or async provider |
placeholder |
string |
'Search...' |
Input placeholder |
closeOnSelect |
boolean |
true |
Close after selecting |
maxResults |
number |
50 |
Max results to show |
theme |
'light' | 'dark' | 'system' |
'system' |
Color theme |
Command Object
Structure of a command in the palette.
interface Command { id: string; // Required: unique identifier label: string; // Required: display text icon?: string; // Optional: emoji or icon shortcut?: string; // Optional: shortcut hint children?: Command[]; // Optional: nested commands action?: () => void; // Optional: callback }
Methods
Available methods on the command palette instance.
| Method | Description |
|---|---|
open() |
Open the command palette |
close() |
Close the command palette |
toggle() |
Toggle open/close state |
setCommands(commands) |
Replace all commands |
destroy() |
Cleanup and remove |
Events
Subscribe to command palette events.
cmd.on('open', () => console.log('Opened')); cmd.on('close', () => console.log('Closed')); cmd.on('select', (command) => console.log('Selected:', command));
Basic Usage
A simple command palette with common actions.
Nested Commands
Drill-down submenus with breadcrumb navigation.
Async Commands
Load commands dynamically from an API with loading states.
Theming
Switch between light and dark themes in real-time.
Styling
Customize with CSS variables.
.bw-cmd-root {
--bw-cmd-bg: #ffffff;
--bw-cmd-text: #1f2937;
--bw-cmd-accent: #3b82f6;
--bw-cmd-border: #e5e7eb;
--bw-cmd-radius: 16px;
}
Accessibility
Built with accessibility as a priority.
Browser Support
Tested and supported in all modern browsers.
| Browser | Version |
|---|---|
| Chrome | 80+ |
| Firefox | 75+ |
| Safari | 14+ |
| Edge | 80+ |