Back to Shark UI

Command

docs/components/command

latest11.3 KB
Original Source

Sections

Components

Utilities

Forms

Hooks

Command

Copy Markdown

Searchable command input with filtering.

DocsAPI

PreviewCode

Suggestions

Linear⌘L

Figma⌘F

Slack⌘S

YouTube⌘Y

Raycast⌘R

Settings

Settings⌘,

Help⌘?

About⌘I

Feedback⌘F

Support⌘S

Updates⌘U

Logout⌘L

Sign out⌘O

Sign in⌘I

Installation#

CLIManual

pnpmbunnpmyarn

pnpm dlx shadcn@latest add @shark/command

Anatomy#

Command
├── CommandInput
├── CommandList
│ ├── CommandEmpty
│ └── CommandGroup
│ ├── CommandGroupLabel
│ └── CommandItem
├── CommandSeparator
├── CommandShortcut
└── CommandFooter

Usage#

import { useFilter, useListCollection } from "@ark-ui/react";
import {
  Command,
  CommandContent,
  CommandEmpty,
  CommandGroup,
  CommandInput,
  CommandItem,
  CommandList,
} from "@/components/ui/command";
const { contains } = useFilter({ sensitivity: "base" });
const { collection, filter } = useListCollection({
  initialItems: [
    { label: "Search", value: "search", group: "Actions" },
    { label: "Settings", value: "settings", group: "Actions" },
  ],
  filter: contains,
  groupBy: (item) => item.group, // optional
});

<Command
  collection={collection}
  onInputValueChange={({ inputValue }) => filter(inputValue)}
>
  <CommandInput placeholder="Search..." />
  <CommandContent>
    <CommandEmpty />
    <CommandList>
      {collection.group().map(([group, items]) => (
        <CommandGroup heading={group} key={group}>
          {items.map((item) => (
            <CommandItem item={item} key={item.value}>
              {item.label}
            </CommandItem>
          ))}
        </CommandGroup>
      ))}
    </CommandList>
  </CommandContent>
</Command>

Examples#

With Dialog#

PreviewCode

Open Command Palette

Groups#

Group related items with CommandGroup and the heading prop.

PreviewCode

Fruit

Apple

Banana

Cherry

Countries

United States

United Kingdom

Germany

Shortcuts#

Display keyboard shortcuts next to items with CommandShortcut.

PreviewCode

New File⌘N

Save⌘S

Copy⌘C

Paste⌘V

Undo⌘Z

Find⌘F

Add hints or actions in the footer with CommandFooter.

PreviewCode

App

Settings⌘,

Keyboard Shortcuts⌘K

Help⌘?

Select

Navigate

Scrollable#

Scrollable command menu with multiple items.

PreviewCode

Frameworks

Angular

Astro

Ember

Gatsby

Next.js

Nuxt.js

React

Remix

Solid

Svelte

Vue.js

Libraries

Alpine.js

jQuery

Lit

Preact

Qwik

Stencil

Meta-frameworks

Blitz.js

Redwood

T3 Stack

TanStack Start

Wasp

API Reference#

Command#

Root component.

PropTypeDefault
collectionListCollection<T>required
value`stringstring[]`
defaultValue`stringstring[]`
onValueChange(details: ValueChangeDetails<T>) => void-
onInputValueChange(details: InputValueChangeDetails) => void-
disabledboolean-
lazyMountbooleantrue
unmountOnExitbooleantrue
classNamestring-

CommandDialog#

Dialog root for the command palette. Same as Dialog.

PropTypeDefault
openboolean-
defaultOpenbooleanfalse
onOpenChange({ open }: OpenChangeDetails) => void-
classNamestring-

CommandDialogTrigger#

Opens the command palette on click. Same as DialogTrigger.

PropTypeDefault
asChildbooleanfalse
classNamestring-

CommandDialogContent#

Container for the command palette inside the dialog.

PropTypeDefault
size`"sm""md"
titlestring"Command Palette"
descriptionstring"Search for a command to run..."
classNamestring-

CommandInput#

Search input with icon. Uses InputGroup for layout.

PropTypeDefault
size`"sm""md"
placeholderstring-
disabledboolean-
classNamestring-

CommandContent#

Scrollable content container for the command list.

PropTypeDefault
classNamestring-

CommandList#

List container for command items.

PropTypeDefault
classNamestring-
asChildboolean-

CommandEmpty#

Content when no items match the filter.

PropTypeDefault
classNamestring-
childrenReactNodeNo results found.
asChildboolean-

CommandGroup#

Groups related items.

PropTypeDefault
heading`stringReactNode`
classNamestring-
asChildboolean-

CommandGroupLabel#

Label for a group.

PropTypeDefault
classNamestring-
asChildboolean-

CommandItem#

A single command or action in the palette.

PropTypeDefault
itemTrequired
classNamestring-

CommandSeparator#

Visual divider between groups or items. Uses Separator.

PropTypeDefault
classNamestring-

CommandShortcut#

Keyboard shortcut hint shown next to a command.

PropTypeDefault
classNamestring-

CommandFooter#

Footer area for hints, tips, or extra actions.

PropTypeDefault
classNamestring-

For a complete list of props, see the Ark UI documentation.

[

Previous page

Combobox ](/docs/components/combobox)[

Next page

Context Menu ](/docs/components/context-menu)

On This Page

InstallationAnatomyUsageExamplesWith DialogGroupsShortcutsWith FooterScrollableAPI ReferenceCommandCommandDialogCommandDialogTriggerCommandDialogContentCommandInputCommandContentCommandListCommandEmptyCommandGroupCommandGroupLabelCommandItemCommandSeparatorCommandShortcutCommandFooter