Examples

App commands

Groups, shortcuts hints and disabled commands.

Preview

Or press Shift + P with the shortcut prop.

Example.tsx
import { Button, CommandPalette, Kbd, Text, type CommandItem } from '@reactloom/ui';
import { useState } from 'react';

const commands: CommandItem[] = [
  { id: 'invoice', label: 'New invoice', group: 'Create', shortcut: 'N' },
  { id: 'customer', label: 'New customer', group: 'Create' },
  { id: 'reports', label: 'Go to reports', group: 'Navigate', keywords: ['analytics', 'charts'] },
  { id: 'settings', label: 'Go to settings', group: 'Navigate' },
  { id: 'theme', label: 'Switch theme', group: 'Preferences', description: 'Light, dark or high contrast' },
  { id: 'export', label: 'Export all data', group: 'Preferences', disabled: true, description: 'Requires the admin role' },
];

export default function Example() {
  const [open, setOpen] = useState(false);
  const [last, setLast] = useState('');
  return (
    <>
      <Button variant="secondary" onClick={() => setOpen(true)}>
        Search commands
      </Button>
      <Text size="sm" role="status">
        {last && `Ran: ${last}`}
      </Text>
      <CommandPalette open={open} onOpenChange={setOpen} commands={commands} onSelect={(command) => setLast(command.label)} />
      <Text size="sm" tone="muted">
        Or press <Kbd>Shift</Kbd> + <Kbd>P</Kbd> with the shortcut prop.
      </Text>
    </>
  );
}

Server search

Control the query and supply results; filter returns 1 to keep them all.

Preview
Example.tsx
import { Button, CommandPalette, type CommandItem } from '@reactloom/ui';
import { useEffect, useState } from 'react';

const people = ['Ada Lovelace', 'Alan Turing', 'Grace Hopper', 'Katherine Johnson', 'Margaret Hamilton', 'Tim Berners-Lee'];

// Server search: control the query, load matching commands, and keep every result (filter returns 1).
export default function Example() {
  const [open, setOpen] = useState(false);
  const [query, setQuery] = useState('');
  const [results, setResults] = useState<CommandItem[]>([]);
  useEffect(() => {
    const timer = setTimeout(() => {
      const q = query.toLowerCase();
      setResults(people.filter((p) => p.toLowerCase().includes(q)).map((p) => ({ id: p, label: p, group: 'People' })));
    }, 150);
    return () => clearTimeout(timer);
  }, [query]);
  return (
    <>
      <Button variant="secondary" onClick={() => setOpen(true)}>
        Find a person
      </Button>
      <CommandPalette
        aria-label="Find a person"
        open={open}
        onOpenChange={setOpen}
        query={query}
        onQueryChange={setQuery}
        commands={results}
        filter={() => 1}
        onSelect={() => {}}
        messages={{ placeholder: 'Search people…' }}
      />
    </>
  );
}

API reference

CommandPalette props
PropTypeDefault
commandsrequired
{ id, label, group?, description?, icon?, shortcut?, keywords?, disabled? }
readonly CommandItem[]—
onSelectrequired
Runs the command; return false to keep the palette open.
(command) => unknown—
open / defaultOpen / onOpenChange
boolean—
shortcut
Opt-in global shortcut, e.g. 'mod+k'.
string—
query / onQueryChange
Control the search text.
string—
filter
Score, or 0 to hide.
(command, query) => number—
aria-label
string'Command palette'
messages
Placeholder, empty and result-count texts.
Partial<CommandPaletteMessages>—

Customization

Extracted from the component’s source on every build, so it matches the code. How the layers fit together is explained in Customization.

State attributes

Target these in your CSS to style states without depending on class names.

AttributeValues
[data-active]present when on
[data-disabled]present when on

Theme tokens it reads

--pl-color-accent-solid --pl-color-accent-subtle --pl-color-border-default --pl-color-fg-default --pl-color-fg-disabled --pl-color-fg-muted --pl-focus-ring-color --pl-font-size-lg --pl-font-size-sm --pl-font-size-xs --pl-radius-md

Accessibility

  • The search field is a combobox with aria-activedescendant; the list is a listbox grouped by heading.
  • The number of results is announced as you type.
  • Focus returns to where it was when the palette closes.
Keyboard interactions
KeyAction
↑ / ↓Move through results
Page Up / Page DownMove by eight
EnterRun the highlighted command
EscapeClose

Usage guidelines

Do

  • Add keywords (synonyms) so people find commands by their own words.
  • Keep the same actions available in menus and buttons.

Don’t

  • Don’t make the palette the only way to reach an action.