Skip to main content
  1. Docs
  2. Components
  3. Actions

Command palette

Search or jump to: anything in the console, by name, from the top bar or ⌘K.

Import
@qeetrix/react/experimental
Status
ExperimentalSince 0.0.6
Renders
<div role="dialog">Server-rendered
Tested
WCAG 2.2 AAaxe on every pull request

01

Import

command-palette.tsx
// Experimental: from the package's experimental entry, until it's stable.
import { CommandPalette } from "@qeetrix/react/experimental";

02

Props

And every native attribute of the element it renders.

PropTypeDefaultWhat it does
groupsreadonly CommandGroup[]requiredThe results, grouped: { label, items }.
onSelect(item: CommandItem) => voidrequiredCalled with the chosen item; the palette then closes.
openboolean—Open, controlled: wire it to the top bar's search.
defaultOpenbooleanfalseOpen to start with, uncontrolled.
onOpenChange(open: boolean) => void—Called as it opens or closes: ⌘K, Escape, a choice.
hotkeybooleantrueOpens and closes with ⌘K or Ctrl+K anywhere on the page.
onQueryChange(query: string) => void—Search yourself as the query changes; groups are then shown as given.
loadingbooleanfalseShows "Searching…", for onQueryChange.
placeholderstring"Search or jump to…"The search box's placeholder.
messagesPartial<…commandPalette>—This palette's words, over QeetrixProvider's.

03

Parts

Each part carries a data-slot, for tests and placement.

data-slotElementWhat it is
command-palette<div role="dialog">The popup, over a backdrop.
command-list<div role="listbox">The results, in their groups.
command-item<div role="option">A result. data-highlighted on the one Enter opens.
command-item-leading<span>Its icon or avatar.
command-item-meta<span>Where it lives, or its kind.

04

A result's fields

CommandItem: what it's called, how it's found, and where it lives.

results.ts
const groups: CommandGroup[] = [
  {
    label: "Settings",
    items: [
      {
        value: "set_mfa",
        label: "Two-step sign-in",
        meta: "Security › Policies",
        icon: ShieldCheckIcon,
        keywords: ["MFA", "2FA", "OTP"],
      },
    ],
  },
  {
    label: "Actions",
    items: [{ value: "invite", label: "Invite a user", icon: UserPlusIcon, shortcut: ["I"] }],
  },
];
Next — Command paletteAccessibility