Navigation
Command Palette
A spotlight-style navigation overlay opened with Cmd+K or Ctrl+K from anywhere.
<script>
import { CommandPalette } from "@codeatlasdev/ui";
import { goto } from "$app/navigation";
let open = $state(false);
</script>
<CommandPalette modules={NAV} onNavigate={(path) => goto(path)} bind:open />
The palette searches the same NavModule[] you pass to AppShellLayout, matching on item label and module label. It registers Cmd+K and Ctrl+K itself on window, so mount it once near the root. It opens as a modal dialog layer. Arrow keys move the selection, Enter navigates and Escape closes.
Open the palette
Click the button or press Cmd+K / Ctrl+K while this page is focused. Picking an item shows its path instead of navigating.
Reference #156 · Pick in the gallery
Code
Keyboard
Type to filter across every module. Queries shorter than minQueryLength keep the full grouped list.
- TypeFilter by label or module name
- ↑ ↓Move through the results
- ↵Navigate to the selected item
- ESCClose the palette
Reference #155 · Pick in the gallery
Code
Async results
Pass search to add server-side results under the local matches. It runs once the user stops typing for searchDebounce ms, receives the trimmed query and an AbortSignal, and returns CommandResult[] ({ id, label, group?, path }). A newer query, closing the palette or unmounting aborts the pending call, so forward the signal to fetch and never apply a stale answer. While it runs the list is aria-busy and a “Searching…” row shows; a rejection shows “Search failed” without hiding local matches; the empty state appears only after the search settles. Progress, the result count and failures are announced through announce().
Results with a group are listed under that heading. Activating one calls onSelect(result) when provided, otherwise onNavigate(result.path).
Async results
A simulated 600 ms server search, grouped, with loading and abort on every new query.
Reference #422 · Pick in the gallery
Code
Props
| Prop | Type | Default | Description |
|---|---|---|---|
modules | NavModule[] | – | Navigation tree to search. Same format as AppShellLayout. |
onNavigate | (path: string) => void | – | Called with the selected item's path. Use goto() in SvelteKit or location in static sites. |
open | boolean | false | Bindable. Controls visibility. Cmd+K and Ctrl+K also toggle it. |
minQueryLength | number | 1 | Trimmed characters needed before the list is filtered. Shorter queries keep the full grouped list. |
search | (query: string, signal: AbortSignal) => Promise<CommandResult[]> | – | Async/server-side search, debounced and aborted on every new query. Throw or reject to show the failed state. |
searchDebounce | number | 200 | Milliseconds without typing before `search` is called. |
shortcut | boolean | true | Opens and closes on Mod+K (Cmd+K / Ctrl+K) anywhere in the window. Turn it off for every palette but one when a page has several, or when the app binds its own shortcut. |
onSelect | (result: CommandResult) => void | – | Called with the whole result when a server result is activated. Replaces `onNavigate` for those results. |
query | string | '' | Bindable current input text. |