Web · Components
CommandPalette
⌘K command palette: quick search, navigating to pages and running commands inside the app.
Live example
Preview
Open with ⌘K / Ctrl+K. Type "dark" (found in a subpage), type "ali" (server results), Mod+Shift+T opens the Theme page directly.
Code
Events
- Events appear here when you interact with the preview.
Import
⌘K command palette: quick search, navigating to pages and running commands inside the app. Commands are given with the items array; fuzzy search, groups, shortcuts, sub-pages, server-side search and recently used are built in.
- Fuzzy search: no case, Turkish character or accent differences; the letters only need to appear in order ("gcm" → "Git commit"). Matches at word starts and contiguous matches rank higher, and matching letters are highlighted.
keywordsanddescriptionare searched too. - Shortcuts:
shortcut(default ⌘K / Ctrl+K) opens the palette. Commands' own shortcuts ("Mod+Shift+L") work even while the palette is closed, so all of the app's shortcuts are defined in one place. - Sub-pages: when a command has
items(orloadItems), selecting it switches the palette to that page; the path shows in the search box. Back: Backspace in an empty box, Esc or the phone's back button. Search at the root also finds sub-page commands (deepSearch). - Async:
itemscan be a Promise/function;loadItemssearches on the server (requested when typing stops; the old request is cancelled). - Commands: if
onSelectreturns a Promise the row shows loading and the palette closes when the work is done;hrefnavigates without a page reload. - Smooth even with thousands of commands: the list is virtualized and filtering doesn't block typing.
- Mobile: opens as a full-height sheet sliding from the bottom; rows are thumb-height, the list stays above the keyboard when it opens, and it closes by pulling down and with the back button (going back first when in a sub-page).
Built on the native <dialog> and shown in the top layer as a popover (opening doesn't stutter no matter how large the page is); focus stays inside and returns to the previous place on close.
Examples
When command shortcuts work.
"global": whenever the palette is on the page (even when closed). This is the way to define all of the app's shortcuts in one place."open": only while the palette is open."none": shortcuts are only displayed, they don't work.
CommandPaletteProps
interfaceProps of the CommandPalette component.
| Name | Type | Default | Description |
|---|---|---|---|
items? | CommandItemsSource | Commands and groups. An array, a Promise or a function called once when the palette opens; filtered fuzzily in the browser when searching. Give a command items for a sub-page. See CommandItem. | |
loadItems? | CommandLoader | Server-side search (e.g. users, documents). Called when typing stops; the returned commands are shown unfiltered below items. Both can be used together: fixed commands + search results. | |
trigger? | ReactElement | Element that opens the palette (e.g. a button looking like "Search… ⌘K"). When omitted the palette opens only with the shortcut or open. | |
shortcut? | string | readonly string[] | false | "Mod+K" | Shortcut(s) that toggle the palette. Turned off with false. Example: ["Mod+K", "/"] ("/" doesn't work inside a text field). |
shortcutScope? | CommandShortcutScope | "global" | When command shortcuts work. See CommandShortcutScope. |
open? | boolean | Whether it is open in controlled use. | |
defaultOpen? | boolean | false | Open initially in uncontrolled use? |
onOpenChange? | (open: boolean) => void | Called with the new state when it opens or closes. | |
onSelect? | (item: CommandItem) => void | Called when any command is selected (before the command's own onSelect). | |
placeholder? | string | "Komut ya da arama yazın…" | Placeholder of the search box. |
emptyMessage? | ReactNode | "Sonuç bulunamadı" | Content shown when there are no results. |
recentKey? | string | localStorage key for "Recently used". When given, run commands are remembered and shown at the top while the search is empty. | |
recentLimit? | number | 5 | Number of remembered commands. |
deepSearch? | boolean | true | Should search also return commands from sub-pages given as arrays? For example typing "dark" at the root finds "Theme › Dark" and runs it directly. |
sort? | boolean | true | Sort search results by match score? With false they stay in the order defined. |
filter? | CommandFilter | Your own matching function; used instead of the built-in fuzzy search. See CommandFilter. | |
footer? | ReactNode | false | Footer. Defaults to keyboard hints on desktop (↑↓ navigate, ↵ select, esc); hidden with false. Not shown on touch screens. | |
mobileSheet? | boolean | true | Turn into a full-height sheet sliding from the bottom on small screens (below 640 px)? |
className? | string | Classes added to the dialog (e.g. max-w-2xl). |
CommandItem
typeA command inside a CommandPalette. See CommandItem in the core.
CommandGroup
typeTitled command group.
CommandEntry
typeAn element of the CommandPalette items array: a command or a { group, items } group.
Command source filtered in the browser: an array, a Promise or a function called once.
CommandLoader
typeLoader that searches on the server.
CommandFilter
typeYour own matching function.
CommandLoadContext
interfaceInfo given to a {@link CommandLoader<N, I>} function.
| Name | Type | Description |
|---|---|---|
query | string | Text in the search box (may be empty). |
signal | AbortSignal | Cancels the old request when a new search starts or the palette closes; pass it to fetch. |