Skip to content
Harness Design System

Command

The Command component provides a flexible UI element for displaying a command palette. It is composed of several subcomponents such as Command.Input, Command.List, Command.Item, and Command.Shortcut to offer a structured and customizable interface.

Usage

import { Command } from '@harnessio/ui/components'
const CommandUsage = () => {
const [isOpen, setIsOpen] = React.useState(false);
return (<>
<Command.Dialog open={isOpen} onOpenChange={setIsOpen}>
<Command.Input placeholder="Type a command or search..." />
<Command.List>
<Command.Empty>No results found.</Command.Empty>
<Command.Group heading="Suggestions">
<Command.Item>Item 1</Command.Item>
<Command.Item>Item 2</Command.Item>
<Command.Separator />
<Command.Item>Item 4</Command.Item>
<Command.Item>Item 3</Command.Item>
</Command.Group>
<Command.Group heading="Commands">
<Command.Item>
Command 1
<Command.Shortcut>⌘K</Command.Shortcut>
</Command.Item>
<Command.Item>
Command 2
<Command.Shortcut>⌘L</Command.Shortcut>
</Command.Item>
</Command.Group>
</Command.List>
</Command.Dialog>
<Button onClick={() => setIsOpen(true)}>Open Command Dialog</Button>
</>)
}

Anatomy

All parts of the Command component can be imported and composed as required.

<Command.Dialog>
<Command.Input placeholder="Type a command or search..." />
<Command.List>
<Command.Empty>No results found.</Command.Empty>
<Command.Group heading="Suggestions">
<Command.Item></Command.Item>
<Command.Item></Command.Item>
</Command.Group>
<Command.Separator />
<Command.Group heading="Commands">
<Command.Item>
<Command.Shortcut>K</Command.Shortcut>
</Command.Item>
<Command.Item>
<Command.Shortcut>L</Command.Shortcut>
</Command.Item>
</Command.Group>
</Command.List>
</Command.Dialog>

API Reference

Root

The Root component serves as the main container for all command elements.

PropRequiredDefaultValue
childrentrueReactNode
classNamefalsestring
labelfalsestring
shouldFilterfalsetrueboolean
filterfalse(value: string, search: string, keywords?: string[]) => number
defaultValuefalsestring
valuefalsestring
onValueChangefalse(value: string) => void
loopfalsefalseboolean
disablePointerSelectionfalsefalseboolean
vimBindingsfalsetrueboolean

Dialog

The Dialog component is used to display the command palette as a dialog.

<Command.Dialog>
<Command.Input placeholder="Type a command or search..." />
<Command.List>
<Command.Empty>No results found.</Command.Empty>
<Command.Group heading="Suggestions">
<Command.Item>Item 1</Command.Item>
<Command.Item>Item 2</Command.Item>
</Command.Group>
<Command.Separator />
<Command.Group heading="Commands">
<Command.Item>
<span>Command 1</span>
<Command.Shortcut>K</Command.Shortcut>
</Command.Item>
<Command.Item>
<span>Command 2</span>
<Command.Shortcut>L</Command.Shortcut>
</Command.Item>
</Command.Group>
</Command.List>
</Command.Dialog>
PropRequiredDefaultValue
childrentrueReactNode
openfalseboolean
defaultOpenfalseboolean
onOpenChangefalse(open: boolean) => void
modalfalseboolean
classNamefalsestring
overlayClassNamefalsestring
contentClassNamefalsestring
containerfalseHTMLElement

Input

The Input component is used to capture user input for the command palette.

<Command.Input placeholder="Type a command or search..." />
PropRequiredDefaultValue
placeholderfalsestring
classNamefalsestring
valuefalsestring
onValueChangefalse(search: string) => void

List

The List component defines the main content area of the command palette.

<Command.List>
<Command.Empty>No results found.</Command.Empty>
<Command.Group heading="Suggestions">
<Command.Item>Item 1</Command.Item>
<Command.Item>Item 2</Command.Item>
</Command.Group>
<Command.Separator />
<Command.Group heading="Commands">
<Command.Item>
<span>Command 1</span>
<Command.Shortcut>K</Command.Shortcut>
</Command.Item>
<Command.Item>
<span>Command 2</span>
<Command.Shortcut>L</Command.Shortcut>
</Command.Item>
</Command.Group>
</Command.List>
PropRequiredDefaultValue
childrentrueReactNode
classNamefalsestring
heightClassNamefalsestring
labelfalsestring

Empty

The Empty component is used to display a message when there are no results.

<Command.Empty>No results found.</Command.Empty>
PropRequiredDefaultValue
childrentrueReactNode
classNamefalsestring

Group

The Group component is used to group related command items.

<Command.Group heading="Suggestions">
<Command.Item>Item 1</Command.Item>
<Command.Item>Item 2</Command.Item>
</Command.Group>
PropRequiredDefaultValue
childrentrueReactNode
headingtruestring
classNamefalsestring
valuefalsestring
forceMountfalseboolean

Item

The Item component defines an individual item within the command palette.

<Command.Item>
<span>Command 1</span>
<Command.Shortcut>K</Command.Shortcut>
</Command.Item>
PropRequiredDefaultValue
childrentrueReactNode
classNamefalsestring
disabledfalseboolean
onSelectfalse(value: string) => void
valuefalsestring
keywordsfalsestring[]
forceMountfalseboolean

Shortcut

The Shortcut component is used to display keyboard shortcuts for command items.

<Command.Item>
<span>Command 1</span>
<Command.Shortcut>K</Command.Shortcut>
</Command.Item>
PropRequiredDefaultValue
childrentrueReactNode
classNamefalsestring

Separator

The Separator component is used to separate groups of command items.

<Command.Separator />
PropRequiredDefaultValue
classNamefalsestring
alwaysRenderfalseboolean