Skip to main content

Overview

The CommandPalette component provides a searchable command palette interface for quick navigation throughout your application. It’s triggered by keyboard shortcuts and supports fuzzy search across all accessible pages.

Features

  • Global Keyboard Shortcut: Cmd+K (Mac) / Ctrl+K (Windows/Linux)
  • Fuzzy Search: Search by page title or path
  • Keyboard Navigation: Arrow keys and Enter for selection
  • Hierarchical Display: Shows breadcrumb paths for nested resources
  • Access Control: Automatically respects route guards and permissions
  • Internationalization: Supports English and Japanese locales

Props

The CommandPalette component has no props. It automatically reads module configurations from the AppShell context.

Usage

Basic Setup

Simply add CommandPalette alongside SidebarLayout as a child of AppShell:

With Locale Configuration

User Experience

Opening the Palette

Users can open the command palette by:
  • Pressing Cmd+K on macOS
  • Pressing Ctrl+K on Windows/Linux
  • Pressing the shortcut again to toggle close

Searching

  1. Type to search for pages by title or path
  2. Results update in real-time as you type
  3. Fuzzy matching helps find pages even with typos
  • Arrow Down: Move to next result
  • Arrow Up: Move to previous result
  • Enter: Navigate to selected page
  • Escape: Close the palette

Result Display

Each result shows:
  • Breadcrumb path: Module > Resource > Sub-resource hierarchy
  • URL path: The actual route path
Example:

Search Behavior

Fuzzy Matching

The search uses fuzzy matching to find pages:
  • “prod” matches “Products”
  • “orddet” matches “Order Details”
  • “set gen” matches “Settings > General”
Search across the full breadcrumb path:
Search by URL paths:

Access Control

The command palette automatically respects route guards:

Advanced Usage

Custom Hook: useCommandPalette

For building custom command palette UIs, use the useCommandPalette hook:

UseCommandPaletteOptions

Array<NavigatableRoute>
required
Array of routes to search through. Each route has:
  • path: URL path
  • title: Page title
  • icon: Optional icon
  • breadcrumb: Array of parent titles

UseCommandPaletteReturn

boolean
Whether the palette is currently open
(open: boolean) => void
Function to control palette visibility
Current search query
Function to update search query
number
Index of currently selected result
Array<NavigatableRoute>
Filtered and sorted search results
(route: NavigatableRoute) => void
Function to navigate to a selected route
(e: React.KeyboardEvent) => void
Keyboard event handler for arrow keys and Enter
React.RefObject<HTMLDivElement | null>
Ref for the results list container (for scroll management)

Helper Functions

Converts navigation items (with access control) to navigable routes:

Internationalization

The command palette uses locale-aware strings:
  • Search placeholder: “Search…” (en) / “検索…” (ja)
  • No results: “No results found” (en) / “結果が見つかりません” (ja)
Set the locale via AppShell:

TypeScript

UseCommandPaletteOptions Type

UseCommandPaletteReturn Type

Styling

The command palette uses Tailwind CSS with the astw: prefix. Customize appearance through CSS variables:

Accessibility

  • Keyboard-first: Fully navigable with keyboard
  • Screen reader support: Proper ARIA labels and roles
  • Focus management: Auto-focuses search input on open
  • Scroll management: Selected item automatically scrolls into view
  • IME support: Ignores key events during IME composition

Performance

  • Suspense integration: Loads navigation data asynchronously
  • Memoized filtering: Optimized search performance
  • Lazy rendering: Only renders when opened

Examples

Complete Implementation

See Also