Moul UIBeta
Components

CommandPalette

Fast, keyboard-first modal command center with search filtering, sections, action shortcuts, and global hotkeys.

CommandPalette

A modal search and quick-action menu inspired by tools like Linear and Raycast, providing global shortcut binding, compound sub-components, and auto-filtering.

Interactive Preview

Press ⌘K or click the button below to launch the Command Palette

Installation

import {
  CommandPalette,
  CommandPaletteInput,
  CommandPaletteList,
  CommandPaletteSection,
  CommandPaletteItem,
  CommandPaletteEmpty,
  CommandPaletteFooter,
  useCommandPalette,
} from '@moul-dev/ui';

Basic Usage

You can manage the palette state with the useCommandPalette hook, which automatically binds the ⌘K / Ctrl+K global keyboard shortcut:

import { useState } from 'react';
import {
  Button,
  CommandPalette,
  CommandPaletteInput,
  CommandPaletteList,
  CommandPaletteSection,
  CommandPaletteItem,
  CommandPaletteEmpty,
  CommandPaletteFooter,
  useCommandPalette,
} from '@moul-dev/ui';

export function Example() {
  const { isOpen, setIsOpen, open } = useCommandPalette();

  return (
    <>
      <Button onPress={open}>
        Open Command Palette (⌘K)
      </Button>

      <CommandPalette isOpen={isOpen} onOpenChange={setIsOpen}>
        <CommandPaletteInput placeholder="Search commands..." />
        <CommandPaletteList>
          <CommandPaletteSection heading="Navigation">
            <CommandPaletteItem
              shortcut={['G', 'H']}
              onAction={() => console.log('Home')}
            >
              Home
            </CommandPaletteItem>
            <CommandPaletteItem
              shortcut={['G', 'D']}
              onAction={() => console.log('Dashboard')}
            >
              Dashboard
            </CommandPaletteItem>
          </CommandPaletteSection>

          <CommandPaletteSection heading="Actions">
            <CommandPaletteItem
              shortcut={['⌘', 'N']}
              description="Create a new document"
              onAction={() => console.log('New Document')}
            >
              New Document
            </CommandPaletteItem>
          </CommandPaletteSection>
        </CommandPaletteList>
        <CommandPaletteEmpty>No matching commands found.</CommandPaletteEmpty>
        <CommandPaletteFooter />
      </CommandPalette>
    </>
  );
}

Keyboard Navigation

  • ↑ / ↓ : Navigate highlighted items
  • ↵ : Execute highlighted command and close palette
  • ESC : Dismiss palette
  • ⌘K / Ctrl+K : Global toggle

Props

CommandPalette

PropTypeDefaultDescription
isOpenboolean—Controlled open state
defaultOpenbooleanfalseUncontrolled default open state
onOpenChange(open: boolean) => void—Handler called when open state changes
shortcutstring | string[]['Meta+k', 'Ctrl+k']Global shortcut key combinations
size'sm' | 'md' | 'lg''md'Maximum width size variant

CommandPaletteItem

PropTypeDefaultDescription
iconReact.ReactNode—Left icon adornment
descriptionReact.ReactNode—Secondary subtitle text
shortcutstring | string[]—Keyboard shortcut keycaps rendered on the right
keywordsstring[]—Additional terms to match against during search filtering
onAction() => void—Callback invoked when item is selected
isDisabledbooleanfalseDisables item interaction

On this page