suiss/ui · Component
Command
A searchable menu of commands, used inline or as a command palette in a dialog.
Command is an open-source component from suiss/ui for React. The @esuiss/ui CLI copies its source into your project, so you own the code.
Command is built on cmdk. The Command root filters and orders its items as people type into CommandInput. CommandList holds the results: CommandGroup sections with a heading, CommandItem rows, CommandSeparator dividers, and a CommandEmpty message shown when nothing matches. CommandShortcut displays a keyboard shortcut at the end of an item.
CommandDialog places a Command in a modal dialog for a command palette. Use a command menu for actions and navigation that people search by name. To pick a value for a form field, use a combobox instead.
Installation
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
Usage
Composition
Use the following composition to build a CommandDialog:
Examples
Empty
A command menu with no items. CommandEmpty shows its message because nothing matches.
Dialog
Wrap the Command in CommandDialog for a command palette opened from a button. It closes with Escape and returns focus to the button.
Dialog open
A command palette that is open when the page loads.
Accessibility
- The input has the
comboboxrole and items have theoptionrole. The highlighted item setsaria-selectedand disabled items setaria-disabled. - The first item is highlighted by default. Arrow keys move the highlight and skip disabled items; Enter selects the highlighted item.
CommandDialogrenders adialognamed by itstitle, moves focus inside when it opens, closes with Escape, and returns focus to the element that opened it.CommandShortcutis hidden on small screens.
API Reference
Command
The root that filters and manages the items.
Also accepts the props of React.ComponentProps<typeof CommandPrimitive>.
Compose CommandInput and CommandList inside Command, and put groups and items in the list. Inside a dialog, Command drops its own background and rounded corners.
CommandDialog
A modal dialog that presents a command menu as a palette.
| Prop | Type | Default |
|---|---|---|
title | string | "Command Palette" |
description | string | "Search for a command to run..." |
className | string | - |
showCloseButton | boolean | false |
children | React.ReactNode | Required |
Also accepts the props of Dialog.
Control the palette with open and onOpenChange.
Control the palette with isOpen and onOpenChange.
title and description name and describe the dialog for assistive technology and are visually hidden. className applies to the dialog's content panel. Pass a Command as the children. The palette uses a translucent, blurred popover background.
CommandInput
The search field, shown with a magnifying glass icon.
Also accepts the props of React.ComponentProps<typeof CommandPrimitive.Input>.
CommandList
The scrollable container for results.
Also accepts the props of React.ComponentProps<typeof CommandPrimitive.List>.
CommandEmpty
Content shown when no items match the search.
Also accepts the props of React.ComponentProps<typeof CommandPrimitive.Empty>.
CommandGroup
A section of related items with an optional heading.
Also accepts the props of React.ComponentProps<typeof CommandPrimitive.Group>.
CommandSeparator
A divider between groups.
Also accepts the props of React.ComponentProps<typeof CommandPrimitive.Separator>.
CommandItem
A selectable command.
Also accepts the props of React.ComponentProps<typeof CommandPrimitive.Item>.
Respond to a chosen item with its onSelect callback, and set disabled on items that are unavailable. The highlighted item gets data-selected and is filled with the primary color, and disabled items get data-disabled="true". An item with data-checked="true" shows a check mark, unless it contains a CommandShortcut.
CommandShortcut
Displays a keyboard shortcut at the end of an item.
| Prop | Type | Default |
|---|---|---|
mod | boolean | - |
Also accepts the props of React.ComponentProps<"span">.
Set mod to prefix the shortcut with the platform modifier key: ⌘ on Apple platforms and Ctrl+ elsewhere.
Each part sets a data-slot, such as command-item or command-input-wrapper, for styling.