BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/thegridcn/command-menu

Command Menu

thegridcn/command-menu
FreeComponent

thegridcn publishes no description for this item.

See it running

Open the demo on thegridcn

thegridcn.com/r/command-menu
Open
This registry sends X-Frame-Options, so its page cannot be embedded here. The link is the same page the frame would have shown.

Install it

npx shadcn@latest add https://thegridcn.com/r/command-menu.json

Source

src/components/thegridcn/command-menu.tsxthegridcn.com/r/command-menu.json · first 6 KB
1"use client";
2
3import * as React from "react";
4import { cn } from "@/lib/utils";
5
6interface CommandMenuItem {
7 description?: string;
8 group?: string;
9 icon?: React.ReactNode;
10 label: string;
11 onSelect?: () => void;
12 shortcut?: string;
13}
14
15interface CommandMenuProps extends React.HTMLAttributes<HTMLDivElement> {
16 items: CommandMenuItem[];
17 label?: string;
18 onOpenChange?: (open: boolean) => void;
19 /** Controlled open state */
20 open?: boolean;
21 placeholder?: string;
22}
23
24export function CommandMenu({
25 items,
26 placeholder = "Type a command...",
27 label,
28 open: controlledOpen,
29 onOpenChange,
30 className,
31 ...props
32}: CommandMenuProps) {
33 const [internalOpen, setInternalOpen] = React.useState(false);
34 const open = controlledOpen ?? internalOpen;
35 const setOpen = onOpenChange ?? setInternalOpen;
36
37 const [query, setQuery] = React.useState("");
38 const inputRef = React.useRef<HTMLInputElement>(null);
39
40 // Filter items
41 const trimmed = query.trim().toLowerCase();
42 const filtered = React.useMemo(() => {
43 if (!trimmed) {
44 return items;
45 }
46 return items.filter(
47 (item) =>
48 item.label.toLowerCase().includes(trimmed) ||
49 item.description?.toLowerCase().includes(trimmed) ||
50 item.group?.toLowerCase().includes(trimmed)
51 );
52 }, [items, trimmed]);
53
54 // Group items
55 const groups = React.useMemo(() => {
56 const map = new Map<string, CommandMenuItem[]>();
57 for (const item of filtered) {
58 const key = item.group || "";
59 const arr = map.get(key) || [];
60 arr.push(item);
61 map.set(key, arr);
62 }
63 return Array.from(map.entries());
64 }, [filtered]);
65
66 // Keyboard navigation
67 const [activeIdx, setActiveIdx] = React.useState(0);
68 React.useEffect(() => setActiveIdx(0), []);
69
70 // Ctrl/Cmd+K to toggle
71 React.useEffect(() => {
72 const handler = (e: KeyboardEvent) => {
73 if ((e.metaKey || e.ctrlKey) && e.key === "k") {
74 e.preventDefault();
75 setOpen(!open);
76 }
77 if (e.key === "Escape" && open) {
78 setOpen(false);
79 }
80 };
81 window.addEventListener("keydown", handler);
82 return () => window.removeEventListener("keydown", handler);
83 }, [open, setOpen]);
84
85 // Focus input on open
86 React.useEffect(() => {
87 if (open) {
88 setQuery("");
89 setTimeout(() => inputRef.current?.focus(), 50);
90 }
91 }, [open]);
92
93 function handleKeyDown(e: React.KeyboardEvent) {
94 if (e.key === "ArrowDown") {
95 e.preventDefault();
96// … truncated

Files it writes

  • src/components/thegridcn/command-menu.tsx

Facts

Registry
thegridcn
Type
registry:component
Access
Free
Files written
1
Licence
the repository states none
First indexed
2026-08-02
Last confirmed
yesterday

Go to the source

Docs on thegridcn thegridcn.com Raw registry item This item as JSON

More from thegridcn

All 139 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
AccordionaccordionthegridcnComponentsFree2 deps
Agent Avataragent-avatarthegridcnComponentsFreeno deps
AlertalertthegridcnComponentsFree1 dep
Alert Dialogalert-dialogthegridcnComponentsFree1 dep
Announcement Barannouncement-barthegridcnComponentsFreeno deps
Anomaly Banneranomaly-bannerthegridcnComponentsFreeno deps
Arrival Panelarrival-panelthegridcnComponentsFreeno deps
Aspect Ratioaspect-ratiothegridcnComponentsFree1 dep
BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex