Command
NavigationA searchable list of commands: <Command.Root> holds a Command.Input that filters the Command.Items (value, keywords, onSelect) and Command.LinkItems (href) in a Command.List, grouped with Command.Group (heading) and divided with Command.Separator. Command.Empty shows when nothing matches, Command.Loading while results load, Command.Shortcut a key hint. Arrow keys move, Enter runs. Command.Dialog puts it all in a dialog as a command palette.
import { Command } from '@limerdev/zest'; Combobox. A short list that fits on screen: use DropdownMenu.Examples
Basic
Typing filters by value and keywords; arrow keys move, Enter runs.
Ran: nothing yet
<script lang="ts">
import FileText from '@lucide/svelte/icons/file-text';
import Folder from '@lucide/svelte/icons/folder';
import Settings from '@lucide/svelte/icons/settings';
import { Command } from '@limerdev/zest';
let last = $state('nothing yet');
</script>
<div class="grid w-full max-w-sm gap-2">
<Command.Root class="border-(length:--border) border-border shadow-box">
<Command.Input placeholder="Search projects and actions…" />
<Command.List>
<Command.Empty>Nothing found.</Command.Empty>
<Command.Group heading="Projects">
<Command.Item value="Zest" onSelect={() => (last = 'Zest')}><Folder /> Zest</Command.Item>
<Command.Item value="Worklog" onSelect={() => (last = 'Worklog')}>
<Folder /> Worklog
</Command.Item>
</Command.Group>
<Command.Separator />
<Command.Group heading="Actions">
<Command.Item
value="New report"
keywords={['create']}
onSelect={() => (last = 'New report')}
>
<FileText /> New report
<Command.Shortcut>⌘N</Command.Shortcut>
</Command.Item>
<Command.Item value="Settings" onSelect={() => (last = 'Settings')}>
<Settings /> Settings
</Command.Item>
</Command.Group>
</Command.List>
</Command.Root>
<p class="text-sm text-muted">Ran: {last}</p>
</div> A palette
Command.Dialog as a palette, opened with ⌘K or Ctrl+K.
<script lang="ts">
import { Button, Command } from '@limerdev/zest';
let open = $state(false);
function onkeydown(event: KeyboardEvent): void {
if (event.key !== 'k' || !(event.metaKey || event.ctrlKey)) return;
event.preventDefault();
open = !open;
}
</script>
<svelte:window {onkeydown} />
<Button variant="outline" onclick={() => (open = true)}>
Search <kbd class="ms-2 text-xs text-muted">⌘K</kbd>
</Button>
<Command.Dialog bind:open>
<Command.Input placeholder="Type a command…" />
<Command.List>
<Command.Empty>Nothing found.</Command.Empty>
<Command.Group heading="Go to">
<Command.Item value="Projects" onSelect={() => (open = false)}>Projects</Command.Item>
<Command.Item value="Reports" onSelect={() => (open = false)}>Reports</Command.Item>
<Command.Item value="Invoices" onSelect={() => (open = false)}>Invoices</Command.Item>
</Command.Group>
</Command.List>
</Command.Dialog> Props
Every part also takes class (merged over its defaults), ref (bindable: the element), children, and child (a snippet that
renders your own element, with props to spread on it).
Command.Root
| Prop | Type | Default | Description |
|---|---|---|---|
| columns | number | null | null | The number of columns in a grid layout. |
| disableInitialScroll | boolean | false | Whether to disable scrolling the selected item into view on initial mount. When true, prevents automatic scrolling when the command menu first renders and selects its first item, but still allows scrolling on subsequent selections. |
| disablePointerSelection | boolean | – | Optionally set to true to disable selection via pointer events. |
| filter | ((value: string, search: string, keywords?: string[] | undefined) => number) | – | A custom filter function for whether each command item should match the query. It should return a number between 0 and 1, with 1 being a perfect match, and 0 being no match, resulting in the item being hidden entirely. By default, it will use the computeCommandScore function exported by this package to compute the score. |
| label | string | – | An accessible label for the command menu. Not visible & only used for screen readers. |
| loop | boolean | – | Optionally set to true to enable looping through the items when the user reaches the end of the list using the keyboard. |
| onStateChange | ((state: Readonly<CommandState>) => void) | – | A function that is called when the command state changes. |
| onValueChange | ((value: string) => void) | – | A function that is called when the selected command menu item changes. It receives the new value as an argument. |
| shouldFilter | boolean | – | Optionally set to false to turn off the automatic filtering and sorting. If false, you must conditionally render valid items yourself. |
| value bindable | string | '' | Optionally provide or bind to the selected command menu item. |
| vimBindings | boolean | true | Set this prop to false to disable the option to use ctrl+n/j/p/k (vim style) navigation. |
Command.Dialog
| Prop | Type | Default | Description |
|---|---|---|---|
| columns | number | null | null | The number of columns in a grid layout. |
| description | string | the Config's `strings.commandPaletteDescription`, else 'Search for a command to run.' | The palette's description for screen readers. |
| disableInitialScroll | boolean | false | Whether to disable scrolling the selected item into view on initial mount. When true, prevents automatic scrolling when the command menu first renders and selects its first item, but still allows scrolling on subsequent selections. |
| disablePointerSelection | boolean | – | Optionally set to true to disable selection via pointer events. |
| filter | ((value: string, search: string, keywords?: string[] | undefined) => number) | – | A custom filter function for whether each command item should match the query. It should return a number between 0 and 1, with 1 being a perfect match, and 0 being no match, resulting in the item being hidden entirely. By default, it will use the computeCommandScore function exported by this package to compute the score. |
| label | string | – | An accessible label for the command menu. Not visible & only used for screen readers. |
| loop | boolean | – | Optionally set to true to enable looping through the items when the user reaches the end of the list using the keyboard. |
| onOpenChange | OnChangeFn<boolean> | – | A callback that is called when the popover's open state changes. |
| onOpenChangeComplete | OnChangeFn<boolean> | – | A callback called when the dialog finishes opening/closing animations. |
| onStateChange | ((state: Readonly<CommandState>) => void) | – | A function that is called when the command state changes. |
| onValueChange | ((value: string) => void) | – | A function that is called when the selected command menu item changes. It receives the new value as an argument. |
| open bindable | boolean | false | The open state of the dialog. |
| portalProps | PortalProps | – | Props for the portal the content renders in: to (the element to render in, the body by default) and disabled (render in place). |
| shouldFilter | boolean | – | Optionally set to false to turn off the automatic filtering and sorting. If false, you must conditionally render valid items yourself. |
| showCloseButton | boolean | false | Show a close button in the corner. |
| title | string | the Config's `strings.commandPalette`, else 'Command palette' | The palette's name for screen readers. |
| value bindable | string | '' | Optionally provide or bind to the selected command menu item. |
| vimBindings | boolean | true | Set this prop to false to disable the option to use ctrl+n/j/p/k (vim style) navigation. |
Command.Empty
| Prop | Type | Default | Description |
|---|---|---|---|
| forceMount | boolean | – | Whether to force mount the group container regardless of filtering logic. |
Command.Group
| Prop | Type | Default | Description |
|---|---|---|---|
| forceMount | boolean | – | Whether to force mount the group container regardless of filtering logic. |
| heading | string | – | The group's heading, which names the group. |
| value | string | – | A unique value for the group. |
Command.Item
| Prop | Type | Default | Description |
|---|---|---|---|
| disabled | boolean | false | Whether the item is disabled. |
| forceMount | boolean | – | Whether to always mount the item regardless of filtering logic. |
| keywords | string[] | – | A list of keywords that will be used to filter the item. |
| onSelect | (() => void) | – | A callback that is fired when the item is selected, either via click or keyboard selection. |
| value | string | – | A unique value for this item that will be used when filtering and ranking the items. If not provided, an attempt will be made to use the textContent of the item. If the textContent is dynamic, you will need to provide a stable unique value for the item. |
Command.LinkItem
| Prop | Type | Default | Description |
|---|---|---|---|
| disabled | boolean | false | Whether the item is disabled. |
| forceMount | boolean | – | Whether to always mount the item regardless of filtering logic. |
| keywords | string[] | – | A list of keywords that will be used to filter the item. |
| onSelect | (() => void) | – | A callback that is fired when the item is selected, either via click or keyboard selection. |
| value | string | – | A unique value for this item that will be used when filtering and ranking the items. If not provided, an attempt will be made to use the textContent of the item. If the textContent is dynamic, you will need to provide a stable unique value for the item. |
Command.Input
| Prop | Type | Default | Description |
|---|---|---|---|
| value bindable | string | '' | The value of the input element, used to search/filter items. |
Command.List
No props of its own beyond the common ones.
Command.Separator
| Prop | Type | Default | Description |
|---|---|---|---|
| forceMount | boolean | – | Whether to force mount the separator container regardless of filtering logic. |
Command.Shortcut
No props of its own beyond the common ones.
Command.Loading
| Prop | Type | Default | Description |
|---|---|---|---|
| progress | number | – | The current progress of the loading state. This is a number between 0 and 100. |