Skip to content
Ballpoint

Command

A command palette: a search field over a list that filters as you type, with arrow keys, Enter and a dialog version for ⌘K.

From shadcn/ui

Installation

pnpm dlx shadcn@latest add @ballpoint/command

Usage

tsx
import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList } from "@/components/ui/command"

<Command>
  <CommandInput placeholder="Type a command or search…" />
  <CommandList>
    <CommandEmpty>No results found.</CommandEmpty>
    <CommandGroup heading="Suggestions">
      <CommandItem onSelect={() => …}>Calendar</CommandItem>
    </CommandGroup>
  </CommandList>
</Command>

Examples

In a dialog

Open the palette from anywhere with ⌘K.

As a picker

Keywords help a search find an item by what it is, not only by its name.

Writing on cream. Try "yellow" or "scrap".

API reference

shouldFilter
default true
boolean

Set false to filter the list yourself, e.g. with results from a server.

filter
(value, search, keywords?) => number

Scores an item against the search, 0 to 1; 0 hides it. The default prefers text that starts with the search, then text that contains it.

loop
default false
boolean

Wrap from the last item to the first with the arrow keys.

framed
default false
boolean

Pencils a box round the palette, for one set on the page. In a CommandDialog the dialog is the box.

CommandItem value / keywords
string / string[]

What the search looks at. The value defaults to the item's text.

CommandItem onSelect
(value: string) => void

Called when the item is chosen with Enter or a click.

CommandDialog
Dialog props

The palette in a dialog; open and onOpenChange work as on Dialog.