Command Palette

The <smart-command-palette> component provides a Cmd+K-style overlay that filters a list of commands by a search query. It follows the Base + Standard + Wrapper pattern with an InjectionToken-based extension mechanism. The abstract CommandPaletteBaseComponent defines the shared API — commands (InputSignal<ICommand[]>), two-way open (ModelSignal<boolean>) and query (ModelSignal<string>), optional ICommandPaletteOptions, cssClass (alias class), a filteredCommands computed signal that performs case-insensitive substring matching on command.label, plus selectCommand(id) and close() behaviors. CommandPaletteStandardComponent is a barebones placeholder concrete implementation. CommandPaletteComponent is the public wrapper that renders CommandPaletteStandardComponent by default and accepts a custom replacement via COMMAND_PALETTE_STANDARD_COMPONENT_TOKEN.


Usage

<smart-button [options]="openButton">Open command palette</smart-button>

<smart-command-palette
  [commands]="commands"
  [options]="options"
  [(open)]="open"
  [(query)]="query"
  (runCommand)="onRunCommand($event)"
/>

@if (lastCommand(); as commandId) {
  <p>Last command: {{ commandId }}</p>
}

The preview renders the code above in an application that registers every preset (provideSmartPresets(), see Installation) and the English translations; without the presets, a component that has one renders its standard implementation instead, for most components unstyled markup.

Components

CommandPaletteComponent (<smart-command-palette>)

Main wrapper component. Renders CommandPaletteStandardComponent by default. When COMMAND_PALETTE_STANDARD_COMPONENT_TOKEN is provided, renders the injected component via NgComponentOutlet, passes it every input (class included), writes its open / query changes back to the wrapper's models and re-emits its runCommand, so [(open)], [(query)] and (runCommand) work the same with the standard, the preset or an implementation of your own.

CommandPaletteStandardComponent (<smart-command-palette-standard>)

Barebones placeholder concrete implementation. Renders a native <dialog [open]> containing an <input type="search"> bound to query and a <ul role="listbox"> with one <li role="option"> per filtered command, or an options.emptyText item ('No results' by default) when nothing matches. Escape anywhere in the document closes an open palette (onEscape(), also inherited by the preset), and so does the dialog's close event. It ignores options.variant and every ICommand field but id and label, and it does not include Tailwind UI styling — it exists solely as the default structural placeholder until a custom implementation is registered through the token. The Cmd+K global shortcut (open) is left to the application.

CommandPaletteBaseComponent (abstract)

Abstract base directive for extending custom command palette implementations. Exposes commands as an InputSignal<ICommand[]> (default []), open and query as two-way ModelSignals (defaults false / ''), options as an InputSignal<ICommandPaletteOptions | undefined>, cssClass as an InputSignal<string> (with alias class), a filteredCommands computed (case-insensitive label substring), a selectCommand(commandId) method that emits the runCommand output and sets open to false, and a close() method that sets open to false. The base binds no keyboard listeners.

API

Inputs

InputTypeDefaultDescription
commandsInputSignal<ICommand[]>[]List of commands available in the palette
openModelSignal<boolean>falseVisibility state (two-way bindable; openChange reports changes)
queryModelSignal<string>''Search query (two-way bindable; queryChange reports changes)
optionsInputSignal<ICommandPaletteOptions | undefined>-Optional configuration
classInputSignal<string>''External CSS classes on the dialog (alias for cssClass)

Outputs

OutputPayloadDescription
runCommand{ commandId: string }Fired when a user selects a command, before the palette closes

ICommand

FieldTypeDefaultDescription
idstringrequiredReported as commandId by runCommand.
labelstringrequiredSearched and shown.
iconstringundefinedPreset only: the leading glyph of the with-icons variant (# when absent).
groupstringundefinedPreset only: the group header of the with-groups variant (Other when absent).
hrefstringundefinedNot read by the built-in implementations (no variant navigates to it); available to a custom implementation or your runCommand handler.
descriptionstringundefinedPreset only: the preview text of the with-preview variant.
imageUrlstringundefinedPreset only: the leading avatar of the with-images variant.

ICommandPaletteOptions

FieldTypeDefaultDescription
variantSmartCommandPaletteVariant'simple'Preset only: the look (see the variants table below). The standard ignores it.
placeholderstringundefinedPlaceholder of the search input.
emptyTextstring'No results'Shown when nothing matches.
ariaLabelstringundefinedAccessible name of the search input.

SmartCommandPaletteVariant is 'simple' | 'with-padding' | 'with-preview' | 'with-images' | 'with-icons' | 'semi-transparent' | 'with-groups' | 'with-footer'.

COMMAND_PALETTE_STANDARD_COMPONENT_TOKEN

InjectionToken that allows replacing the default CommandPaletteStandardComponent with a custom implementation. Provide a Type<CommandPaletteBaseComponent> to override; the wrapper passes it every input it declares and forwards its open, query and runCommand.

Extending the base class

import {
  ChangeDetectionStrategy,
  Component,
  computed,
  ViewEncapsulation,
} from '@angular/core';

import {
  CommandPaletteBaseComponent,
  CommandPaletteComponent,
  COMMAND_PALETTE_STANDARD_COMPONENT_TOKEN,
  ICommand,
  ICommandPaletteOptions,
} from '@smartsoft001/angular';

/**
 * A custom command palette built on `CommandPaletteBaseComponent`.
 *
 * The base owns the `commands` input, the `open` and `query` models, the
 * `filteredCommands` computed and `selectCommand()` / `close()`. Note that the
 * base binds no keyboard listeners: handling Escape or a global Cmd+K is the
 * implementation's job. Call `selectCommand()` rather than emitting
 * `runCommand` by hand, because it also closes the palette.
 */
@Component({
  selector: 'docs-custom-command-palette',
  template: `
    <div [class]="containerClasses()" [hidden]="!open()">
      <input
        type="search"
        class="docs-command-palette__search"
        [value]="query()"
        [attr.placeholder]="options()?.placeholder ?? null"
        (input)="onQueryChange($event)"
      />
      <ul role="listbox" class="docs-command-palette__list">
        @for (command of filteredCommands(); track command.id) {
          <li role="option" [attr.aria-selected]="false">
            <button type="button" (click)="selectCommand(command.id)">
              {{ command.label }}
            </button>
          </li>
        } @empty {
          <li class="docs-command-palette__empty">
            {{ options()?.emptyText ?? 'No results' }}
          </li>
        }
      </ul>
    </div>
  `,
  encapsulation: ViewEncapsulation.None,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class CustomCommandPaletteComponent extends CommandPaletteBaseComponent {
  containerClasses = computed(() =>
    ['docs-command-palette', this.cssClass()].filter(Boolean).join(' '),
  );

  onQueryChange(event: Event): void {
    this.query.set((event.target as HTMLInputElement).value);
  }
}

/**
 * Registering the implementation against
 * `COMMAND_PALETTE_STANDARD_COMPONENT_TOKEN` makes every
 * `<smart-command-palette>` in this injector render it instead of the standard
 * variation.
 */
@Component({
  selector: 'docs-command-palette-custom-example',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [CommandPaletteComponent],
  providers: [
    {
      provide: COMMAND_PALETTE_STANDARD_COMPONENT_TOKEN,
      useValue: CustomCommandPaletteComponent,
    },
  ],
  template: `
    <smart-command-palette
      [commands]="commands"
      [options]="options"
      [open]="true"
    />
  `,
})
export class CommandPaletteCustomExampleComponent {
  commands: ICommand[] = [
    { id: 'new-file', label: 'New file' },
    { id: 'open-settings', label: 'Open settings' },
    { id: 'toggle-theme', label: 'Toggle theme' },
  ];

  options: ICommandPaletteOptions = {
    placeholder: 'Search commands…',
    emptyText: 'Nothing matches.',
  };
}

Preset

CommandPalettePresetComponent (<smart-command-palette-preset>) is the styled, production-ready replacement for the barebones standard component. It extends CommandPaletteStandardComponent, so all filtering (filteredCommands), query handling (onQueryChange), selection (selectCommand → emit runCommand + close), close() and the Escape listener are inherited unchanged; the preset only adds the visual layer driven by options.variant.

Register it under COMMAND_PALETTE_STANDARD_COMPONENT_TOKEN ({ provide: COMMAND_PALETTE_STANDARD_COMPONENT_TOKEN, useValue: CommandPalettePresetComponent }) to restyle every <smart-command-palette>, register every preset at once with provideSmartPresets(), or use the <smart-command-palette-preset> selector directly (it takes the extra classes as class or [cssClass]).

The base look is a native <dialog [open]> styled smart:mx-auto smart:mt-16 smart:w-full smart:max-w-xl smart:rounded-xl with a gray border, white/dark:bg-gray-800 surface and smart:shadow-xl; a search input with a leading magnifier SVG (ps-11, focus:ring-blue-500); a <ul role="listbox"> with smart:divide-y rows that hover smart:bg-gray-100 dark:bg-gray-700; and a centered smart:text-gray-500 empty state using options.emptyText (fallback No results). All Tailwind utilities are smart:-prefixed with explicit dark: twins in the same template; the class recipes are internal to the preset (not exported).

Variants (options.variant, default simple)

VariantRendering
simpleBase dialog + listbox, opaque white/dark:gray-800 surface.
with-paddingLooser row padding (smart:px-6 smart:py-4) for a roomier list.
with-iconsLeading square glyph per row from ICommand.icon (falls back to # when absent).
with-imagesLeading rounded avatar per row from ICommand.imageUrl (rows without an image show no avatar).
semi-transparentTranslucent smart:bg-white/90 dark:bg-gray-800/90 smart:backdrop-blur dialog surface.
with-groupsGrouped rows under uppercase headers (data-role="group") from ICommand.group.
with-footerAdds a bottom bar (data-role="footer") with a result count and Enter / Esc hint text.
with-previewTwo-pane layout: half-width list + a preview panel showing the hovered (default first) command.

with-groups groups by ICommand.group; commands without a group fall under an Other header. with-preview uses ICommand.description for the preview body and widens the dialog to smart:max-w-3xl.

data-role hooks

The template exposes stable data-role attributes for testing/targeting: dialog, search-wrap, search, list, item, item-icon, item-image, group, empty, footer, preview-layout, preview.

Source

The component lives in packages/shared/angular/src/lib/components/command-palette and is documented for Claude Code by the angular-components-command-palette skill.

SmartCommandPalette is a search dialog over a list of commands: the user types, the commands are filtered by a case-insensitive substring of their label, and clicking one reports onRunCommand({ commandId }) and closes the palette. Both the open state (open / defaultOpen / onOpenChange) and the search text (query / defaultQuery / onQueryChange) can be controlled or left to the component. SmartCommandPaletteStandard is a native <dialog> with a listbox; SmartCommandPalettePreset adds the visual variants of options.variant.


Usage

import { useState } from 'react';

import {
  ICommand,
  ICommandPaletteOptions,
  SmartButton,
  SmartCommandPalette,
} from '@smartsoft001/react';

const commands: ICommand[] = [
  { id: 'new-project', label: 'New project' },
  { id: 'invite-member', label: 'Invite team member' },
  { id: 'open-settings', label: 'Open settings' },
];

const options: ICommandPaletteOptions = {
  placeholder: 'Search commands...',
  emptyText: 'No commands found.',
  ariaLabel: 'Search commands',
};

export function CommandPaletteUsageExample() {
  const [open, setOpen] = useState(false);
  const [query, setQuery] = useState('');
  const [lastCommand, setLastCommand] = useState<string | null>(null);

  return (
    <>
      <SmartButton options={{ click: () => setOpen(true) }}>
        Open command palette
      </SmartButton>

      <SmartCommandPalette
        commands={commands}
        options={options}
        open={open}
        onOpenChange={setOpen}
        query={query}
        onQueryChange={setQuery}
        onRunCommand={({ commandId }) => setLastCommand(commandId)}
      />

      {lastCommand && <p>Last command: {lastCommand}</p>}
    </>
  );
}

The preview renders the code above in an application that registers every preset (SMART_PRESET_COMPONENTS on SmartProvider, see Installation) and the English translations; without the presets, a component that has one renders its standard implementation instead, for most components unstyled markup.

Exports

All from @smartsoft001/react.

ExportKindWhat it is
SmartCommandPalettecomponentRenders the implementation registered as components['command-palette'] on SmartProvider, SmartCommandPaletteStandard by default.
SmartCommandPalettePresetcomponentStyled command-palette variation (preset).
SmartCommandPaletteStandardcomponentThe default command palette: a native <dialog> with a search input and a listbox of the filtered commands.
useCommandPalettehookThe behaviour every command-palette variant shares: the open and query models (controlled or uncontrolled), the commands filtered by a case-insensitive label substring, and selectCommand, which reports the command through onRunCommand and closes the palette.

The preset's class helpers (getCommandPaletteDialogClasses, getCommandPaletteListClasses, getCommandPaletteItemClasses, COMMAND_PALETTE_SEARCH_WRAP, COMMAND_PALETTE_SEARCH_ICON, COMMAND_PALETTE_SEARCH, COMMAND_PALETTE_ITEM_ICON, COMMAND_PALETTE_ITEM_IMAGE, COMMAND_PALETTE_ITEM_LABEL, COMMAND_PALETTE_GROUP, COMMAND_PALETTE_EMPTY, COMMAND_PALETTE_FOOTER, COMMAND_PALETTE_PREVIEW_LAYOUT, COMMAND_PALETTE_PREVIEW) are exported too, for a custom implementation that wants the preset look.

Props and Types

SmartCommandPaletteProps

PropTypeDefaultDescription
commands?ICommand[][]The commands to search.
open?boolean—Whether the palette is open. Controlled when set; leave it undefined to let the palette keep its own state, starting from defaultOpen.
defaultOpen?booleanfalseInitial open state when uncontrolled.
onOpenChange?(open: boolean) => void—Called when the palette opens or closes (also after a command runs).
query?string—The search text. Controlled when set; leave it undefined to let the palette keep its own state, starting from defaultQuery.
defaultQuery?string''Initial search text when uncontrolled.
onQueryChange?(query: string) => void—Called with the new search text.
options?ICommandPaletteOptions—Variant and texts.
className?string—Classes on the dialog.
onRunCommand?(event: ICommandPaletteRunCommand) => void—Called with the id of the clicked command, before the palette closes.

ICommandPaletteOptions

FieldTypeDefaultDescription
variant?SmartCommandPaletteVariant'simple'The preset look; the standard ignores it.
placeholder?string—Placeholder of the search input.
emptyText?string'No results'Shown when nothing matches.
ariaLabel?string—Accessible name of the search input.

ICommandPaletteRunCommand

Passed to onRunCommand when a command is chosen.

FieldTypeDefaultDescription
commandIdstringrequiredThe id of the chosen command.

ICommand

FieldTypeDefaultDescription
idstringrequiredReported as commandId.
labelstringrequiredSearched and shown.
icon?string—Shown by the preset's with-icons variant.
group?string—Group header in the preset's with-groups variant.
href?string—Carried for your own use; no variant navigates to it (handle it in onRunCommand).
description?string—Secondary text (e.g. in the preview pane).
imageUrl?string—Shown by the preset's with-images variant.
  • SmartCommandPaletteVariant: 'simple' \| 'with-padding' \| 'with-preview' \| 'with-images' \| 'with-icons' \| 'semi-transparent' \| 'with-groups' \| 'with-footer'

Replacing the Implementation

SmartCommandPalette renders the component registered under the 'command-palette' key of SmartProvider's components, and SmartCommandPaletteStandard when nothing is registered there. Every SmartCommandPalette below the provider then renders the registered component, which receives the same props.

SmartCommandPalettePreset is the styled (preset) implementation: register it under the 'command-palette' key of SmartProvider's components, render it directly in place of SmartCommandPalette, or spread SMART_PRESET_COMPONENTS on the provider to register every preset at once (see the react-provider skill). Pass components as a stable object (a module constant or a memoised value), or the context changes on every render.

The useCommandPalette hook

The behaviour every command-palette variant shares: the open and query models (controlled or uncontrolled), the commands filtered by a case-insensitive label substring, and selectCommand, which reports the command through onRunCommand and closes the palette.

ReturnsTypeDescription
openbooleanThe open state (controlled or internal).
querystringThe search text (controlled or internal).
setQuery(next: string) => voidSets the search text and calls onQueryChange.
filteredCommandsICommand[]The commands whose label contains the query (case-insensitive).
selectCommand(commandId: string) => voidCalls onRunCommand({ commandId }), then closes the palette.
close() => voidCloses the palette and calls onOpenChange(false).
import {
  ICommand,
  ICommandPaletteOptions,
  SmartCommandPalette,
  SmartCommandPaletteProps,
  SmartProvider,
  useCommandPalette,
} from '@smartsoft001/react';

/**
 * A custom command palette built on `useCommandPalette`.
 *
 * The hook owns the `open` and `query` state (controlled or not), the
 * `filteredCommands` and `selectCommand()` / `close()`. It binds no keyboard
 * listeners: handling Escape or a global Cmd+K is the implementation's job.
 * Call `selectCommand()` rather than `onRunCommand` by hand, because it also
 * closes the palette.
 */
export function CustomCommandPalette(props: SmartCommandPaletteProps) {
  const { options, className } = props;
  const { open, query, setQuery, filteredCommands, selectCommand } =
    useCommandPalette(props);

  return (
    <div
      className={['docs-command-palette', className].filter(Boolean).join(' ')}
      hidden={!open}
    >
      <input
        type="search"
        className="docs-command-palette__search"
        value={query}
        placeholder={options?.placeholder}
        onChange={(event) => setQuery(event.target.value)}
      />
      <ul role="listbox" className="docs-command-palette__list">
        {filteredCommands.map((command) => (
          <li key={command.id} role="option" aria-selected={false}>
            <button type="button" onClick={() => selectCommand(command.id)}>
              {command.label}
            </button>
          </li>
        ))}
        {filteredCommands.length === 0 && (
          <li className="docs-command-palette__empty">
            {options?.emptyText ?? 'No results'}
          </li>
        )}
      </ul>
    </div>
  );
}

// A module constant: a new object on every render would change the context.
const components = { 'command-palette': CustomCommandPalette };

const commands: ICommand[] = [
  { id: 'new-file', label: 'New file' },
  { id: 'open-settings', label: 'Open settings' },
  { id: 'toggle-theme', label: 'Toggle theme' },
];

const options: ICommandPaletteOptions = {
  placeholder: 'Search commands…',
  emptyText: 'Nothing matches.',
};

// Every <SmartCommandPalette> below the provider renders CustomCommandPalette.
export function CommandPaletteCustomExample() {
  return (
    <SmartProvider components={components}>
      <SmartCommandPalette commands={commands} options={options} defaultOpen />
    </SmartProvider>
  );
}

Styling

  • The standard and preset palettes are native <dialog> elements: pressing Escape anywhere in the document closes an open palette, and so does the dialog's close event. useCommandPalette binds no keyboard listener, so a custom implementation handles Escape (and any Ctrl+K shortcut) itself.
  • SmartCommandPalettePreset renders the variants simple, with-padding, with-preview, with-images, with-icons, semi-transparent, with-groups and with-footer, with smart:dark: variants.

Source

The component lives in packages/shared/react/src/lib/components/command-palette and is documented for Claude Code by the react-components-command-palette skill.