Skip to content

Overlays

Command palette

Also calledcommand launcherquick action search

A searchable panel for finding and running application actions or navigating to destinations without browsing menus.

How people describe it

  • “search box floating over the page for actions”
  • “type a command to find something to do”
  • “popup list of commands filtered as I type”

Good for

  • Quick access to many commands
  • Keyboard-friendly navigation in complex apps

Don’t mix it up with

  • Chooses a field value; a command palette runs actions or opens destinations.

What your library calls it

LIBRARYCALLS IT
shadcn/uiCommand

Accessibility checklist

  • Label the dialog and search input
  • Trap focus in the open dialog and restore it when dismissed
  • Keep results keyboard reachable and announce no matches

Try it

Press ⌘K or Ctrl+K too

    • New file⌘N
    • Open settings⌘,
    • Copy link⌘L
    • Go to dashboard⌘D
    • Go to projects⌘P
    • Sign out⌘Q

↑↓ to move · Enter to run · Esc to close

Open it, type to filter, ↑ ↓ to move, Enter to run.

Prompt

Add a command palette that filters actions as I type and closes with Escape.

~19 estimated prompt tokensDetailed: ~76 estimated prompt tokens

Rough estimate for prompt text only; actual counts vary by model and context.

"use client";
import { useId, useRef, useState } from "react";

export function CommandPalette({ onAction }: { onAction: (id: string) => void }) {
  const dialog = useRef<HTMLDialogElement>(null);
  const titleId = useId();
  const searchId = useId();
  const [query, setQuery] = useState("");
  const commands = [
    { id: "new-project", label: "Create a project" },
    { id: "settings", label: "Open settings" },
  ];
  const matches = commands.filter((item) => item.label.toLowerCase().includes(query.toLowerCase()));
  return (
    <>
      <button type="button" className="min-h-11 min-w-11 px-3" onClick={() => { setQuery(""); dialog.current?.showModal(); }}>Open commands</button>
      <dialog ref={dialog} aria-labelledby={titleId} className="m-auto w-full max-w-md rounded-xl p-4 backdrop:bg-black/40">
        <h2 id={titleId}>Commands</h2>
        <label htmlFor={searchId}>Find an action</label>
        <input id={searchId} type="search" value={query} onChange={(event) => setQuery(event.target.value)} className="min-h-11 w-full border p-2" />
        <ul aria-label="Matching commands">
          {matches.map((item) => (
            <li key={item.id}>
              <button type="button" className="min-h-11 w-full p-2 text-left" onClick={() => { dialog.current?.close(); onAction(item.id); }}>{item.label}</button>
            </li>
          ))}
        </ul>
        <p role="status">{matches.length ? `${matches.length} actions available` : "No matching actions"}</p>
        <button type="button" className="min-h-11 min-w-11 px-3" onClick={() => dialog.current?.close()}>Close</button>
      </dialog>
    </>
  );
}

Used in

Explore website blueprints that use this component.