React Native · Components
CommandPalette
Command palette: quick search, navigating to pages and running commands inside the app.
Live example
The preview runs in the browser with the web component; the native component takes the same props and looks the same on iOS and Android.
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
CommandPalette
componentCommand palette: quick search, navigating to pages and running commands inside the app. Same data and behavior as CommandPalette on web; commands are given with the items array (the same array works on both platforms).
- Fuzzy search: Ignores case, Turkish characters and accents; the letters only need to appear in order ("gcm" → "Git commit"). Matches at word starts and adjacent matches rank higher, matched letters are highlighted.
keywordsanddescriptionare searched too. The scoring lives in core and is the same as on web. - Sub pages: When a command has
items(orloadItems), selecting it moves the palette to that page; the path shows in the search box. Back: the arrow in the header, backspace in an empty box, or the Android back button. Search at the root also finds commands in sub pages (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;hrefopens withopenLink. - Keyboard: The keyboard's "Go" key (or Enter on a hardware keyboard) runs the first result; the first result is highlighted while typing.
- Phone: A full-height sheet sliding up from the bottom; when the keyboard opens the list stays above it, and it closes by pulling down and with the back button (on a sub page the back button first returns to the parent page). Tablet: Opens centered.
- Smooth with thousands of commands: the list is virtualized and filtering does not block typing.
Command shortcuts (shortcut) and the palette shortcut are not available on native because touch devices have no such keys.
Examples
CommandPaletteStyles
interfaceStyles of the inner parts of CommandPalette.
| Name | Type | Description |
|---|---|---|
panel? | ViewStyle | Window. |
header? | ViewStyle | Search row. |
item? | ViewStyle | Command row. |
group? | ViewStyle | Group heading. |
CommandPaletteProps
interfaceProps of the CommandPalette component (same names as on web).
| Name | Type | Default | Description |
|---|---|---|---|
items? | CommandItemsSource | Commands and groups. Can be an array, a Promise or a function called once when the palette opens; filtered fuzzily on the device while 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 below items without filtering. | |
trigger? | ReactElement | Element that opens the palette (e.g. a button that looks like "Search…"). If omitted the palette opens only via open. | |
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 | "Recently used" key. When given, executed commands are remembered and shown at the top while the search is empty. Give storage to persist them. | |
recentLimit? | number | 5 | Number of remembered commands. |
storage? | PreferenceStorage | Where recent items are stored (a @yasinsensoy/native/storage store can be passed directly). If omitted they are forgotten when the app closes. | |
deepSearch? | boolean | true | Should search also return commands of sub pages given as arrays? For example, typing "dark" at the root finds "Theme › Dark" and runs it directly. |
sort? | boolean | true | Should search results be sorted by match score? With false they keep the order they were defined in. |
filter? | CommandFilter | Your own matching function; used instead of the built-in fuzzy search. See CommandFilter. | |
mobileSheet? | boolean | true | Turn into a full-height sheet sliding up from the bottom on a phone (below 640 dp)? With false it opens centered on every screen. |
styles? | CommandPaletteStyles | Styles of the inner parts. See CommandPaletteStyles. | |
testID? | string | Test id (given to the window). |
CommandItem
typeA command in CommandPalette (same fields as on web).
label,description,badge: text or an element.icon: an icon name or an element.href: navigated to withopenLinkwhen selected (a link registered with the Navigator opens inside the app).onSelect: if it returns a Promise the row shows loading and the palette closes when the work is done (stays open withkeepOpen).items/loadItems: a sub page opens when selected.shortcut: not shown and does nothing on native (accepted so the same data can be used as on web).
CommandGroup
typeA command group with a heading: { group, items }.
CommandEntry
typeAn element of the items array: a command or a group.
A filtered command source: an array, a Promise or a function called once.
CommandLoader
typeA loader that searches on the server.
CommandFilter
typeYour own matching function: returns a score; 0 or less means no match.
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. |