Documentation

Command

A command palette on cmdk: a search input over a filtered list of commands, inline or in a dialog.

WebBetaNavigation

Web only — React, from @krizaka/ui/command. Beta: its API may still change in a minor version.

When to use

  • To reach any page or action of an app from the keyboard (⌘K): CommandDialog.
  • For a searchable list of choices inside a panel: Command.Root inline.
  • When results come from the server: shouldFilter={false} and Command.Loading.

When not to use

  • For a short list of actions on one item.Use instead: Dropdown menu
  • For a choice among a few options in a form: use a select or radios.Use instead: Radio group
  • As the only way to navigate: keep the visible navigation.

Installation

Install

npm install @krizaka/ui@beta @krizaka/tailwind@beta @krizaka/tokens@beta tailwindcss

Styles

@import "tailwindcss";
@import "@krizaka/tailwind";
@import "@krizaka/ui/tailwind.css";

Import

import { Command, CommandDialog } from "@krizaka/ui/command";

Examples

Inline

In a card: the input, groups, shortcuts, a disabled item.

In a dialog

CommandDialog: the palette of an app, opened from a button or a shortcut.

Props

CommandRoot

The palette: value / onValueChange (the active item), shouldFilter, filter, loop.

PropTypeDefaultDescription
labelstring—Accessible label for this command menu. Not shown visibly. The accessible name of the palette — passed translated ("Search", "Commands").

CommandInput

The search field (value / onValueChange for the query), with a magnifier.

PropTypeDefaultDescription
placeholderrequiredstring—What to type — passed translated. The input is named by the palette's label.
trailingReactNode—After the input, inside the bar: a spinner, a clear button.

CommandList

PropTypeDefaultDescription
labelstring—Accessible label for this List of suggestions. Not shown visibly. The accessible name of the list of results — passed translated ("Suggestions", "Results").

CommandEmpty

Shown by cmdk only when no item matches.

PropTypeDefaultDescription
emptyLabelrequiredReactNode—Shown when nothing matches — passed translated.

CommandDialog

The palette in a dialog (Radix: focus trap, Escape, focus return). The dialog is named by label; it has no close button — Escape and a click outside close it — and the input takes the focus when it opens.

PropTypeDefaultDescription
contentPropsOmit<DialogContentProps & RefAttributes<HTMLDivElement> & DialogVariants & { closeLabel?: string; hideClose: true; } & { ...; }, "children" | ... 1 more ... | "hideClose">—Passed to Dialog.Content: size, container, className of the dialog.
defaultOpenboolean—Open at first, uncontrolled.
footerReactNode—Under the palette, inside the dialog: shortcuts, a "see all results" link.
labelstring—Accessible label for this command menu. Not shown visibly. The accessible name of the palette — passed translated ("Search", "Commands").
onOpenChange((open: boolean) => void)—Called when it opens or closes (Escape, a click outside, a shortcut of the product).
openboolean—Open or closed (controlled), with onOpenChange.

Accessibility

  • A combobox and a listbox: the input owns aria-activedescendant, the results are options.
  • label names the palette, Command.List label the results.
  • CommandDialog traps the focus in the platform's Dialog and puts it in the input when it opens.

Keyboard

KeysAction
Arrow keysMove through the results.
EnterRuns the highlighted command.
EscCloses the CommandDialog and returns the focus.

Best practices

  • Group the commands (Command.Group heading) and show their shortcuts with Command.Shortcut.
  • Add keywords so a command is found by the words people type, not only by its label.
  • Always say what an empty search means with Command.Empty emptyLabel.

Generated from the code of @krizaka/ui 2.0.0-beta.6: its meta.ts, its examples and its types.Edit this documentation on GitHub

On this page