Overview
TheCommandPalette 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
TheCommandPalette component has no props. It automatically reads module configurations from the AppShell context.
Usage
Basic Setup
Simply addCommandPalette alongside SidebarLayout as a child of AppShell:
With Locale Configuration
User Experience
Opening the Palette
Users can open the command palette by:- Pressing
Cmd+Kon macOS - Pressing
Ctrl+Kon Windows/Linux - Pressing the shortcut again to toggle close
Searching
- Type to search for pages by title or path
- Results update in real-time as you type
- Fuzzy matching helps find pages even with typos
Navigation
- 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
Search Behavior
Fuzzy Matching
The search uses fuzzy matching to find pages:- “prod” matches “Products”
- “orddet” matches “Order Details”
- “set gen” matches “Settings > General”
Breadcrumb Search
Search across the full breadcrumb path:Path Search
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 theuseCommandPalette hook:
UseCommandPaletteOptions
Array<NavigatableRoute>
required
Array of routes to search through. Each route has:
path: URL pathtitle: Page titleicon: Optional iconbreadcrumb: Array of parent titles
UseCommandPaletteReturn
boolean
Whether the palette is currently open
(open: boolean) => void
Function to control palette visibility
string
Current search query
(search: string) => void
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
navItemsToRoutes
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)
AppShell:
TypeScript
NavigatableRoute Type
UseCommandPaletteOptions Type
UseCommandPaletteReturn Type
Styling
The command palette uses Tailwind CSS with theastw: 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
- AppShell - Root component configuration
- SidebarLayout - Default layout component
- Guards & Permissions - Access control for routes
- Internationalization - Multi-language support