Updated
Command Menu
Customize
Width580px
Recents4
Installation
npx shadcn@latest add https://uibrik.com/r/command-menu.jsonInstall the packages
npm install @tabler/icons-react motionAdd the cn helper
Imports
cnfrom@/lib/utils, whichshadcn initcreates. Add it by hand without shadcn.Copy the source into your project
components/uibrik/command-menu/command-menu.tsx"use client"; import { type ReactNode, useEffect, useId, useMemo, useRef, useState, useSyncExternalStore, type KeyboardEvent } from "react"; import { createPortal } from "react-dom"; import { motion } from "motion/react"; import { IconChevronRight, IconCornerDownLeft, IconSearch } from "@tabler/icons-react"; import { cn } from "@/lib/utils"; export type CommandItem = { id: string; label: string; /** Which filter the item belongs to. Also picks its group heading. */ type: string; icon?: ReactNode; /** Quiet text after the label. Searched, but never highlighted. */ description?: string; /** Extra words that find the item, e.g. "add member" for "Invite teammate". */ keywords?: string[]; /** Keys shown on the right, one chip each. "mod" becomes ⌘ or Ctrl. With `hotkeys` on, ["mod", "N"] is a chord and ["G", "D"] a sequence. */ shortcut?: string[]; /** Shown dimmed and skipped by the keyboard; it can't be run. */ disabled?: boolean; /** Opens a nested page of commands instead of running. */ children?: CommandItem[];
Adds the files to
components/uibrik/command-menu and installs @tabler/icons-react and motion. With the @uibrik namespace set up: npx shadcn@latest add @uibrik/command-menu.Usage
import { CommandMenu } from "@/components/uibrik/command-menu/command-menu";const items = [ { id: "intro", type: "docs", label: "Introduction", keywords: ["overview", "about"] }, { id: "install", type: "docs", label: "Installation", keywords: ["setup", "cli", "npm"] }, // …11 more];const filters = [ { id: "docs", label: "Get started" }, { id: "components", label: "Components" }, // …1 more];<CommandMenu placeholder="Search docs and components" shortcut="k" showFilters highlight footer blur width={580} hotkeys maxRecents={4} items={items} filters={filters} searchDelay={200} maxResults={100} defaultOpen={false} recentsKey="command-menu-recents" onSearch={(query, signal) => {}} onOpenChange={(open) => {}} onSelect={(item) => {}} // renderItem={(item, state) => {}} // labels={…} // open={false}/>Where to use Command Menu
⌘K in SaaS apps
Fuzzy and server search with grouped results lets users jump anywhere from the keyboard.
Docs site search
Recents and nested pages help readers return to the page they had open yesterday.
Pairs with Search
Power-user actions
Hotkeys and filter pills turn the menu into a launcher for actions, not just pages.
Props
CommandMenu- placeholder
- Type string
- "Search docs and components"
- Text in the empty field and on the trigger.
- shortcut
- Type string
- "k"
- Key that toggles the menu with ⌘ / Ctrl. Empty turns the shortcut off.
- showFilters
- Type boolean
- true
- Show the filter pills. Tab cycles them from the keyboard.
- highlight
- Type boolean
- true
- Bold the letters of the label that matched the search.
- footer
- Type boolean
- true
- Keyboard hints and the result count under the list.
- blur
- Type boolean
- true
- Blur the page behind the menu.
- width
- Type number
- 580
- Widest the menu gets.
- hotkeys
- Type boolean
- true
- Run an item's shortcut from anywhere on the page while the menu is closed.
- maxRecents
- Type number
- 4
- Recently run commands listed first while the field is empty. 0 turns them off.
- items
- Type CommandItem[]
- SAMPLE_ITEMS
- What the menu can find or run: { id, label, type, icon?, description?, keywords?, shortcut?, disabled?, children?, onSelect? }. Give an item children to open a nested page.
- filters
- Type CommandFilter[]
- SAMPLE_FILTERS
- Filter pills and group headings, as { id, label }. An item's type picks its filter.
- onSearch
- Type (query: string, signal: AbortSignal) => Promise<CommandItem[]>
- –
- Fetches results from a server as the user types, shown beside the local ones. Called once typing pauses; abort the signal when a newer search starts. The demo searches a fake customer list this way.
- searchDelay
- Type number
- 200
- Wait after the last keystroke before calling onSearch, in ms.
- maxResults
- Type number
- 100
- Most rows shown at once. Longer lists are cut off; searching narrows them.
- renderItem
- Type (item: CommandItem, state: { active: boolean; label: ReactNode }) => ReactNode
- –
- Draws a row's contents yourself, e.g. a status badge or an amount. The row's highlight, height and click stay.
- labels
- Type Partial<CommandLabels>
- DEFAULT_LABELS
- Replaces any of the menu's text, for translation or your own wording.
- open
- Type boolean
- –
- Controlled open state. Leave out to let the menu keep its own.
- defaultOpen
- Type boolean
- false
- Whether it starts open.
- onOpenChange
- Type (open: boolean) => void
- –
- Called when the menu opens or closes.
- onSelect
- Type (item: CommandItem) => void
- –
- Called after a command runs, alongside its own onSelect.
- recentsKey
- Type string
- "command-menu-recents"
- localStorage key for recents.
- className
- Type string
- –
- Classes for the trigger button.