Black Friday · Save 40% on Intent UI Design licenses with code UI2026.

Command Menu

Loading...

Installation

Add the component with the CLI.

npx shadcn@latest add @intentui/command-menu

Composed components

When you install this component via the CLI, it automatically loads all composed components, so you don’t need to add them individually.

Manual installation

Install the dependencies, then copy the component source into your project.

npm install react-aria-components @heroicons/react cn

Anatomy

"use client"

import {
  Cog6ToothIcon,
  CreditCardIcon,
  CubeIcon,
  DocumentTextIcon,
  HomeIcon,
  ShieldCheckIcon,
} from '@heroicons/react/24/outline'
import { useState } from 'react'
import { Avatar } from '@/components/ui/avatar'
import { Button } from '@/components/ui/button'
import {
  CommandMenu,
  CommandMenuItem,
  CommandMenuLabel,
  CommandMenuList,
  CommandMenuSearch,
  CommandMenuSection,
  CommandMenuShortcut,
} from '@/components/ui/command-menu'
const users = [
  {
    id: 1,
    name: 'Barbara Kirlin Sr.',
    image_url: 'https://i.pravatar.cc/150?img=1',
  },
  {
    id: 2,
    name: 'Rosemarie Koch',
    image_url: 'https://i.pravatar.cc/150?img=2',
  },
  {
    id: 3,
    name: 'Mrs. Reva Heaney Jr.',
    image_url: 'https://i.pravatar.cc/150?img=3',
  },
  {
    id: 5,
    name: 'Bria Ziemann',
    image_url: 'https://i.pravatar.cc/150?img=5',
  },
  {
    id: 6,
    name: 'Heloise Borer Sr.',
    image_url: 'https://i.pravatar.cc/150?img=6',
  },
]
export function CommandPalette() {
  const [isOpen, setIsOpen] = useState(false)
  return (
    <>
      <Button intent="outline" onPress={() => setIsOpen(true)}>
        Open
      </Button>
      <CommandMenu isOpen={isOpen} onOpenChange={setIsOpen}>
        <CommandMenuSearch placeholder="Quick search..." />
        <CommandMenuList>
          <CommandMenuSection label="Pages">
            <CommandMenuItem textValue="Home" href="#">
              <HomeIcon />
              <CommandMenuLabel>Home</CommandMenuLabel>
            </CommandMenuItem>
            <CommandMenuItem textValue="Docs" href="#">
              <DocumentTextIcon />
              <CommandMenuLabel>Docs</CommandMenuLabel>
              <CommandMenuShortcut>⌘k</CommandMenuShortcut>
            </CommandMenuItem>
            <CommandMenuItem textValue="Components" href="#">
              <CubeIcon />
              <CommandMenuLabel>Components</CommandMenuLabel>
            </CommandMenuItem>
          </CommandMenuSection>
          <CommandMenuSection label="Dashboard">
            <CommandMenuItem textValue="billing" href="#">
              <CreditCardIcon />
              <CommandMenuLabel>Billing</CommandMenuLabel>
            </CommandMenuItem>
            <CommandMenuItem textValue="settings" href="#">
              <Cog6ToothIcon />
              <CommandMenuLabel>Settings</CommandMenuLabel>
              <CommandMenuShortcut>⌘s</CommandMenuShortcut>
            </CommandMenuItem>
            <CommandMenuItem textValue="security" href="#">
              <ShieldCheckIcon />
              <CommandMenuLabel>Security</CommandMenuLabel>
            </CommandMenuItem>
          </CommandMenuSection>
          <CommandMenuSection label="Team">
            {users.map((user) => (
              <CommandMenuItem textValue={user.name} key={user.id}>
                <Avatar src={user.image_url} />
                <CommandMenuLabel>{user.name}</CommandMenuLabel>
              </CommandMenuItem>
            ))}
          </CommandMenuSection>
        </CommandMenuList>
      </CommandMenu>
    </>
  )
}

Examples

Separator

Place CommandMenuSeparator inside CommandMenuSection to separate items.

Loading...

Keyboard

Display keyboard shortcut labels alongside command items.

Loading...

Trigger by keyboard

Open the command menu with a keyboard shortcut.

⌘ /

Danger

Highlight a command item as dangerous by changing its color to red, indicating a warning.

Loading...

Controlled

Control the search text with inputValue and onInputChange. Set textValue on each CommandMenuItem so the search input can filter it.

Loading...

Use onAction to run an action when an item is selected:

<CommandItem onAction={() => console.log('share intentui.com/d/command')} />

Pending

Set isPending to show a loading indicator while fetching data.

Loading...

Disabled

Disable items in the command menu to make them non-interactive, appearing grayed out.

Loading...

Hide escape button

To hide the escape button, set escapeButton to false. View this setup in the Command Description section.

<CommandMenu
  escapeButton={false}
  isOpen={isOpen}
  onOpenChange={setIsOpen}
/>

Description

Add supporting text to command items with CommandMenuDescription.

Loading...

Hide scrollbar

Add this utility to your CSS, then apply scrollbar-none to CommandMenuList:

@utility scrollbar-none {
  -ms-overflow-style: none; /* Internet Explorer and Edge */
  scrollbar-width: none; /* Firefox */
  &::-webkit-scrollbar {
    display: none; /* Safari and Chrome */
  }
}
<CommandMenuList className="scrollbar-none">

Close the command palette when the user navigates to another page.

Inertia.js

Listen for Inertia’s navigate event and close the palette:

export function CommandPalette({ open, setOpen }: Props) {
  useEffect(() => {
    router.on('navigate', () => setOpen(false))
  }, [pathname, setOpen])
  return (...)

Next.js

When using Next.js, you can use the usePathname hook to close the command palette when you navigate to a new page.

export function CommandPalette({ open, setOpen }: Props) {
  const pathname = usePathname()

  useEffect(() => {
    setOpen(false)
  }, [pathname])
  return (...)

On action

To close the command palette when an action is performed, use the onAction prop. This prop accepts a callback function that is called when an action is performed. The callback function receives the action object as an argument.

<CommandMenu
  onAction={(action) => {
    if (action.type === 'close') {
      setIsOpen(false)
    }
  }}
/>

Component API

CommandMenu

CommandMenu extends the React Aria Components <Autocomplete> component.

aria-labelstring
classNamestring
isDismissableboolean
Default: true
overlayPick<ModalOverlayProps, "className">
shortcutstring
sizekeyof typeof sizes
Default: lg

CommandMenuDescription

CommandMenuDescription extends the Intent UI <MenuDescription> component.

classNamestring

CommandMenuFooter

CommandMenuFooter extends the native <div> element.

classNamestring

CommandMenuItem

CommandMenuItem extends the Intent UI <MenuItem> component.

classNamestring

CommandMenuLabel

CommandMenuLabel extends the Intent UI <MenuLabel> component.

classNamestring

CommandMenuList

CommandMenuList extends the React Aria Components <Menu> component.

classNamestring

CommandMenuSearch

CommandMenuSearch extends the React Aria Components <SearchField> component.

classNamestring
placeholderstring

CommandMenuSection

CommandMenuSection extends the Intent UI <MenuSection> component.

classNamestring

CommandMenuSeparator

CommandMenuSeparator extends the Intent UI <MenuSeparator> component.

classNamestring

CommandMenuShortcut

CommandMenuShortcut extends the Intent UI <DropdownKeyboard> component.

classNamestring

See the React Aria for the full API reference.

Design