React Command Palette (⌘K)
A glass React command palette that opens with ⌘K or Ctrl+K, with fuzzy search, recent picks first and nested pages.
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/command.jsonWorkspace
Jump anywhere without the mouse.
CommandPaletteuseCommandShortcuthighlightMatchdefaultCommandPaletteLabels- +2 more
⌘K anywhere
Try "dsh" for Dashboard, "prefs" (a hidden keyword) for Settings, or "dark" to reach a theme inside the "Change theme…" page straight from the top. Enter runs a command; Escape or Backspace in an empty field steps back out of a page. Your last picks show under Recent next time.
import { useState } from "react";
import { Button } from "@/components/sheenui/button/button";
import { CommandPalette } from "@/components/sheenui/command/command";
import { type CommandItem } from "@/components/sheenui/command/parts/model";
import { useCommandShortcut } from "@/components/sheenui/command/use-command-shortcut";
import { KbdShortcut } from "@/components/sheenui/kbd/kbd";
// Package build (after the first npm release, or a packed tarball): import { Button, CommandPalette, KbdShortcut, useCommandShortcut, type CommandItem } from "@sheenui/theme";
import { House as HomeIcon, Search as SearchIcon } from "lucide-react";
// This example also uses button: npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/button.json
export function Example() {
const [open, setOpen] = useState(false);
const setTheme = (theme: "light" | "dark") => document.documentElement.setAttribute("data-theme", theme);
const commands: CommandItem[] = [
{ id: "dashboard", label: "Dashboard", group: "Navigation", icon: <HomeIcon />, onSelect: () => location.assign("/") },
{
id: "settings",
label: "Settings",
keywords: ["preferences", "account"],
group: "Navigation",
shortcut: "mod+,",
onSelect: () => location.assign("/settings"),
},
{
id: "theme",
label: "Change theme…",
group: "Actions",
placeholder: "Choose a theme…",
items: [
{ id: "theme-light", label: "Light", onSelect: () => setTheme("light") },
{ id: "theme-dark", label: "Dark", onSelect: () => setTheme("dark") },
],
},
{ id: "export", label: "Export workspace", group: "Actions", disabled: true },
];
// Only need the shortcut? The hook works on its own ("mod+k" by default):
useCommandShortcut(() => setOpen((value) => !value));
// ⌘K / Ctrl+K toggles the palette; focus returns to the trigger on close.
return (
<CommandPalette
items={commands}
open={open}
onOpenChange={setOpen}
recentStorageKey="my-app:recent-commands"
trigger={
<Button variant="glass" leading={<SearchIcon />} trailing={<KbdShortcut keys="mod+k" className="ms-auto" />}>
Search or jump to…
</Button>
}
/>
);
}Files to copy
9 folders · 18 files · 4 packages
- From
theme/src/ components/command/components/dialog/components/drawer/parts/sheet.tsxcomponents/kbd/components/spinner/hooks/{use-controllable.ts, use-latest.ts, use-media-query.ts, use-preferences.ts, use-virtual-window.ts}motion/{presets.ts, tokens.ts}lib/{cn.ts, form.ts, group-segments.ts, ime.ts, modal-flag.ts, modal-tab-trap.ts, page-size.ts, popup-motion.ts, state-light.tsx, warn-once.ts}styles/
- shadcn CLI
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/command.jsonRegistry item: command. The styles need the Tailwind v4 glass UI setup.- The examples also use
components/button/hooks/use-magnetic.tsmotion/gate.ts
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/button.json- Packages
pnpm add @base-ui/react clsx motion tailwind-merge
Thousands of commands
Long lists are windowed on their own (virtualized defaults to auto, above 200 results), so the palette stays fast with a big command list. This one lists 3,000 commands and sets maxResults high enough to search them all: arrow down, press Page Down, or type a number.
import { Button } from "@/components/sheenui/button/button";
import { CommandPalette } from "@/components/sheenui/command/command";
// Package build (after the first npm release, or a packed tarball): import { Button, CommandPalette } from "@sheenui/theme";
// This example also uses button: npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/button.json
const commands = Array.from({ length: 3000 }, (_, i) => ({
id: `cmd-${i + 1}`,
label: `Command ${String(i + 1).padStart(4, "0")}`,
group: i < 1500 ? "Alpha" : "Beta",
}));
export function Example() {
return (
<CommandPalette
items={commands}
maxResults={3000}
shortcut={false}
trigger={<Button variant="glass">Browse 3,000 commands</Button>}
/>
);
}Your own results
filter={false} shows the items you pass, as they are: search a server in onQueryChange and set loading meanwhile. Matches are still highlighted. This one has no global shortcut (shortcut={false}).
import { useState } from "react";
import { Button } from "@/components/sheenui/button/button";
import { CommandPalette } from "@/components/sheenui/command/command";
// Package build (after the first npm release, or a packed tarball): import { Button, CommandPalette } from "@sheenui/theme";
// This example also uses button: npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/button.json
type Person = { id: string; name: string; role: string };
// Your data hook: queries your API for the text typed so far.
declare function usePeopleSearch(query: string): { data: Person[]; isLoading: boolean };
export function Example() {
const [query, setQuery] = useState("");
const { data: people, isLoading } = usePeopleSearch(query);
return (
<CommandPalette
trigger={<Button variant="glass">Find a person</Button>}
shortcut={false}
items={people.map((p) => ({ id: p.id, label: p.name, description: p.role, group: "People" }))}
query={query}
onQueryChange={setQuery}
filter={false}
loading={isLoading}
maxRecent={0}
labels={{ placeholder: "Search people…", inputLabel: "Search people" }}
/>
);
}API
CommandPalette
CommandPaletteLabels keys and English defaults (17)
KbdLabels keys and English defaults (4)
CommandItem
useCommandShortcut(callback, options)
Keyboard
Accessibility
- The field is an ARIA combobox that owns a listbox (aria-activedescendant), so focus never leaves it.
- The result count is announced politely and usage instructions are read on open; the dialog is named by labels.title.
- Shortcut hints expose aria-keyshortcuts. Focus returns to the trigger on close. Every string is translatable.
All exports on this page
CommandPalette— Command palette (Cmd/Ctrl+K): a glass dialog with a fuzzy search field over grouped commands.defaultCommandPaletteLabels— The English strings of CommandPalette.highlightMatch— Wrap the matched characters in <mark>.useCommandShortcut— Global keyboard shortcut, ⌘K / Ctrl+K by default.
When to use the command palette
- Use it as a Cmd+K menu, a global Cmd+K or Ctrl+K search in a dashboard, where people jump to pages and run actions without leaving the keyboard, with fuzzy matching on label, description and hidden keywords. As a cmdk alternative it is a styled command palette with a search field, groups and keyboard shortcuts built in.
- Use it for an app with many settings, where commands with nested items open a page such as Change theme, and deepSearch finds those inner commands straight from the top level. Use it for Spotlight search in React: press the shortcut, type, and pick a command.
- Use it for async results by passing filter={false} and fetching in onQueryChange, so you can show server search results while the palette still highlights the matched characters.
- Skip it when the user simply picks a value for a form field; Combobox or Select belong inside the form, and a Dropdown menu fits a short fixed list of actions behind one button.
- Pair it with KbdShortcut to display the key beside the trigger button, the useCommandShortcut hook for your own bindings, and Button as the trigger element that opens it.
SheenUI Command Palette or cmdk?
cmdk is a popular unstyled command menu for React that you compose and style yourself. SheenUI's CommandPalette is styled glass and ships the behaviors most apps then build: groups, nested pages, fuzzy search with highlighted matches, recent commands and a Cmd or Ctrl+K shortcut. Pick cmdk when you want full control of the markup and styling; pick this one when you want those behaviors ready to use and the source to copy.
Frequently asked questions
Related pages
67 components pages in all: browse them on All components.
By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .