GitHub

Command

Search-first command palette surface for app navigation, shortcuts, and filtered action discovery with a small set of composable subcomponents.

AccessibleDark ModeKeyboard Nav

Install

$npx react-principles add command
search

Navigation

Actions

02

Code Snippet

src/ui/Command.tsx
import { Command } from "@/ui/Command";

<Command>
  <Command.Input placeholder="Search commands..." />
  <Command.List>
    <Command.Group>
      <Command.Label>Navigation</Command.Label>
      <Command.Item value="go-home">Go to home</Command.Item>
      <Command.Item value="open-docs">Open docs</Command.Item>
    </Command.Group>
  </Command.List>
</Command>
03

Copy-Paste (Single File)

Command.tsx
import { createContext, useContext, useMemo, useState, type HTMLAttributes, type InputHTMLAttributes, type ReactNode } from "react";
import { cn } from "@/lib/utils";

interface CommandContextValue {
  query: string;
  setQuery: (query: string) => void;
}
04

Props

PropTypeDefaultDescription
Command.InputInputHTMLAttributes<HTMLInputElement>Search field bound to the internal command query state.
Command.ListHTMLAttributes<HTMLDivElement>Scrollable container for filtered command groups and items.
Command.Item.valuestringPrimary searchable string used for filtering the item.
Command.Item.keywordsstring[]Additional search terms matched against the current query.
Command.GroupHTMLAttributes<HTMLDivElement>Logical grouping wrapper for related command items.
Command.LabelHTMLAttributes<HTMLParagraphElement>Uppercase section label for a command group.
Command.SeparatorHTMLAttributes<HTMLDivElement>Visual divider between command groups.
Command.Empty{ className?: string; children?: ReactNode }"No results"Fallback message shown when the query has no matches.
react-principles