Skip to main content

CommandPalette

A global command launcher modal that enables fast keyboard-driven navigation and execution of actions. Implements sectioned command groups, fuzzy filtering, keyboard navigation, shortcut display, controlled/uncontrolled state, and accessible dialog semantics.


Usage

Basic Command Palette

import { CommandPalette } from '@nofinite/nui';

<CommandPalette
sections={[
{
title: 'Navigation',
items: [
{ id: 'home', label: 'Go Home', onSelect: () => router.push('/') },
{
id: 'profile',
label: 'Open Profile',
onSelect: () => router.push('/profile'),
},
],
},
]}
/>;

Controlled Open State

const [open, setOpen] = useState(false);

<CommandPalette open={open} onOpenChange={setOpen} sections={sections} />;

Commands with Icons & Shortcuts

<CommandPalette
sections={[
{
title: 'Editor',
items: [
{
id: 'save',
label: 'Save File',
shortcut: 'Ctrl S',
icon: <SaveIcon />,
onSelect: saveFile,
},
],
},
]}
/>

Commands with Descriptions

<CommandPalette
sections={[
{
title: 'Search',
items: [
{
id: 'docs',
label: 'Search Docs',
description: 'Open documentation search',
onSelect: openDocs,
},
],
},
]}
/>

Props

PropTypeDefaultDescription
sectionsCommandSection[]Sectioned command groups
placeholderstring"Search commands…"Input placeholder
classNamestring""Custom class override
openbooleanControlled open state
onOpenChange(open: boolean) => voidTriggered when open state changes

CommandItem Structure

FieldTypeDescription
idstringUnique command identifier
labelstringPrimary command label
iconReactNodeOptional leading icon
shortcutstringKeyboard shortcut hint
descriptionstringSecondary explanatory text
onSelect() => voidHandler executed on selection

Variants

<CommandPalette sections={sections} />                 // Default palette
<CommandPalette open /> // Controlled open palette
<CommandPalette sections={sectionsWithIcons} /> // Icon commands
<CommandPalette sections={sectionsWithDescriptions} /> // Rich command items

Available variants

  • default — Standard command launcher
  • controlled — External state-driven palette
  • rich-items — Commands with icons/description
  • shortcut-enabled — Commands showing keyboard hints

Guidelines

  • Use default for basic navigation actions
  • Use controlled when integrating with app-level UI triggers
  • Use rich-items for complex contextual commands
  • Use shortcut-enabled for productivity workflows

States

StateDescription
closedPalette hidden
openModal visible
activeKeyboard-highlighted command
filteredSearch-filtered results
emptyNo results state

Keyboard Interaction

KeyBehavior
Cmd/Ctrl + KToggle palette
Arrow DownMove selection forward
Arrow UpMove selection backward
EnterExecute selected command
EscapeClose palette
TypingFilter commands

Accessibility

  • Uses dialog + listbox pattern
  • Supports full keyboard navigation
  • Active item uses aria-selected
  • Screen reader friendly structured sections
  • Click outside and Escape close behavior
  • Auto-focus search input on open

Design Tokens

:root {
--nui-radius-xl: 16px;
--nui-space-2: 8px;
--nui-space-3: 12px;
--nui-space-4: 16px;
--nui-space-12: 48px;

--nui-bg-surface: #ffffff;
--nui-bg-subtle: #f3f4f6;
--nui-border-default: #e5e7eb;
--nui-fg-default: #111827;
--nui-fg-muted: #6b7280;
--nui-color-primary: #3b82f6;
}

Best Practices

Do

  • Use for global navigation and command execution
  • Group commands into semantic sections
  • Provide meaningful descriptions for discoverability
  • Include shortcuts for power users
  • Keep command labels concise and action-oriented

Don’t

  • Overload palette with rarely used commands
  • Mix unrelated command groups in same section
  • Use long descriptions that increase visual noise
  • Remove keyboard navigation support
  • Hide critical commands behind filtering