Skip to main content
BlocksCommand MenuCommand menu with grouped actions

shadcn/ui Command Menu blockCommand menu with grouped actions

A shadcn/ui command menu dialog opened with ⌘K that lists suggested actions and settings in labelled groups, each with an icon and keyboard shortcut hint. Built with the shadcn/ui Command and Dialog components (cmdk under the hood), with fuzzy search, empty state, and full keyboard navigation. A solid starting point for any app-wide command palette.

Free@shadcnpro/command-menu-01

Preview

Installation

npx shadcn@latest add @shadcnpro/command-menu-01

First time? Add the @shadcnpro registry to components.json as shown in Installation. Free blocks install without a license key.

Let your AI editor install it

The shadcn/ui Pro MCP server lets Cursor, Claude Code and VS Code find and install blocks like Command menu with grouped actions from one prompt. It is included in every Pro plan.

Add the shadcn/ui components

Command menu with grouped actions uses Button, Command and Kbd.

npx shadcn@latest add button command kbd

Install the npm packages

npm install lucide-react

Copy the code

Paste it into components/blocks/command-menu-01.tsx.

components/blocks/command-menu-01.tsx
'use client';

import * as React from 'react';
import {
  ActivityIcon,
  BarChart3Icon,
  BellIcon,
  BookOpenIcon,
  CalendarDaysIcon,
  CircleHelpIcon,
  ClipboardListIcon,
  FlagIcon,
  FolderKanbanIcon,
  InboxIcon,
  KeyboardIcon,
  LayoutGridIcon,
  LineChartIcon,
  LogOutIcon,
  PaletteIcon,
  PieChartIcon,
  SettingsIcon,
  TimerIcon,
  UsersRoundIcon,
} from 'lucide-react';
import { Button } from '@/components/ui/button';
import {
  CommandDialog,
  CommandEmpty,
  CommandGroup,
  CommandInput,
  CommandItem,
  CommandList,
} from '@/components/ui/command';
import { Kbd } from '@/components/ui/kbd';

const navigateItems = [
  { icon: LayoutGridIcon, label: 'Home' },
  { icon: FolderKanbanIcon, label: 'Boards' },
  { icon: ClipboardListIcon, label: 'My work' },
  { icon: CalendarDaysIcon, label: 'Schedule' },
  { icon: UsersRoundIcon, label: 'People' },
  { icon: InboxIcon, label: 'Inbox' },
  { icon: BookOpenIcon, label: 'Wiki' },
  { icon: BellIcon, label: 'Activity' },
  { icon: TimerIcon, label: 'Timesheets' },
  { icon: FlagIcon, label: 'Milestones' },
];

const insightItems = [
  { icon: BarChart3Icon, label: 'Summary' },
  { icon: LineChartIcon, label: 'Velocity' },
  { icon: PieChartIcon, label: 'Workload' },
  { icon: ActivityIcon, label: 'Health score' },
];

const settingsItems = [
  { icon: SettingsIcon, label: 'Workspace settings' },
  { icon: PaletteIcon, label: 'Theme' },
  { icon: KeyboardIcon, label: 'Shortcuts' },
  { icon: CircleHelpIcon, label: 'Help center' },
  { icon: LogOutIcon, label: 'Log out' },
];

/**
 * Command menu with grouped actions.
 */
export default function CommandMenu01() {
  const [open, setOpen] = React.useState(true);

  React.useEffect(() => {
    const down = (e: KeyboardEvent) => {
      if (e.key === 'k' && (e.metaKey || e.ctrlKey)) {
        e.preventDefault();
        setOpen((prev) => !prev);
      }
    };
    document.addEventListener('keydown', down);
    return () => document.removeEventListener('keydown', down);
  }, []);

  return (
    <>
      <Button onClick={() => setOpen(true)} type="button" variant="outline">
        Open command menu
        <Kbd className="ml-1">⌘K</Kbd>
      </Button>

      <CommandDialog
        className="-translate-y-1/2 top-1/2"
        description="Jump to a page or run an action"
        onOpenChange={setOpen}
        open={open}
        showCloseButton={false}
        title="Command menu"
      >
        <CommandInput className="h-12" placeholder="Where do you want to go?" />
        <CommandList className="h-[320px] max-h-[320px]">
          <CommandEmpty>Nothing matches that search.</CommandEmpty>
          <CommandGroup heading="Navigate">
            {navigateItems.map((item) => (
              <CommandItem key={item.label} onSelect={() => setOpen(false)}>
                <item.icon className="mr-2 size-5" />
                <span>{item.label}</span>
              </CommandItem>
            ))}
          </CommandGroup>
          <CommandGroup heading="Insights">
            {insightItems.map((item) => (
              <CommandItem key={item.label} onSelect={() => setOpen(false)}>
                <item.icon className="mr-2 size-5" />
                <span>{item.label}</span>
              </CommandItem>
            ))}
          </CommandGroup>
          <CommandGroup heading="Settings">
            {settingsItems.map((item) => (
              <CommandItem key={item.label} onSelect={() => setOpen(false)}>
                <item.icon className="mr-2 size-5" />
                <span>{item.label}</span>
              </CommandItem>
            ))}
          </CommandGroup>
        </CommandList>
        <div className="flex h-12 items-center justify-end border-t px-3">
          <button
            className="flex items-center gap-1 text-muted-foreground text-sm hover:text-foreground"
            onClick={() => setOpen(false)}
            type="button"
          >
            <span>Close</span>
            <Kbd className="ml-1">Esc</Kbd>
          </button>
        </div>
      </CommandDialog>
    </>
  );
}

Use it

Import it where you need it and update the import path to match your project.

Usage
import CommandMenu01 from '@/components/blocks/command-menu-01';

export default function Page() {
  return <CommandMenu01 />;
}

Overview

Command menu with grouped actions is a free command menu block for shadcn/ui. It is built from the Button, Command and Kbd components with lucide-react, and installs as a single file you own and can edit.

It only uses semantic tokens such as bg-background, text-muted-foreground and border-border, so it follows your theme, radius and fonts and switches with dark mode. It is responsive from desktop to mobile; the width controls above the preview show each size. The same layout is in the shadcn/ui Pro Figma kit, so design and code start from one source.

Category
Command Menu
Component library
Radix UI (radix-ui)
Also available for
Base UI, React Aria
Built with
Button, Command and Kbd
npm packages
lucide-react
Files
components/blocks/command-menu-01.tsx
Access
Free, installs without a license key

Frequently asked questions

Pricing, installation and Radix UI details for Command menu with grouped actions.