All components
Chewypixel component

Command

A command palette whose highlight glides between results as you move through them.

Installation

npx shadcn@latest add https://chewypixel.io/r/command.json

Usage

"use client";

import { useEffect, useState } from "react";
import {
  CommandDialog,
  CommandEmpty,
  CommandFooter,
  CommandGroup,
  CommandInput,
  CommandItem,
  CommandList,
} from "@/components/ui/command";

const pages = ["Dashboard", "Orders", "Customers", "Settings"];

export function CommandMenu() {
  const [open, setOpen] = useState(false);

  useEffect(() => {
    function onKeyDown(event: KeyboardEvent) {
      if (event.key === "k" && (event.metaKey || event.ctrlKey)) {
        event.preventDefault();
        setOpen((current) => !current);
      }
    }
    document.addEventListener("keydown", onKeyDown);
    return () => document.removeEventListener("keydown", onKeyDown);
  }, []);

  return (
    <CommandDialog open={open} onOpenChange={setOpen}>
      <CommandInput placeholder="Search pages…" />
      <CommandList>
        <CommandEmpty>No sweet matches. Try another page name.</CommandEmpty>
        <CommandGroup heading="Pages">
          {pages.map((page) => (
            <CommandItem key={page} value={page} onSelect={() => setOpen(false)}>
              {page}
            </CommandItem>
          ))}
        </CommandGroup>
      </CommandList>
      <CommandFooter />
    </CommandDialog>
  );
}

Props

value

A unique value for the item. The gliding highlight needs it; items without one get a plain highlight. Goes on CommandItem.

string

onSelect

Called when the item is clicked or picked with Enter. Goes on CommandItem.

(value: string) => void

open

Whether the palette is open. Goes on CommandDialog, along with onOpenChange.

boolean

title

The dialog's title for screen readers. Goes on CommandDialog, along with description.

string = "Search"

Released under the MIT License.

More components

See them in a real app

These components come from Mochi, our admin dashboard template built with Next.js, shadcn/ui and Motion.