# Command (@limerdev/zest) A searchable list of commands: `` holds a `Command.Input` that filters the `Command.Item`s (`value`, `keywords`, `onSelect`) and `Command.LinkItem`s (`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. - Category: Navigation - Import: `import { Command } from '@limerdev/zest'` - Bits UI: `Command`, https://bits-ui.com/docs/components/command - Exports: `Command.Root`, `Command.Dialog`, `Command.Empty`, `Command.Group`, `Command.Item`, `Command.LinkItem`, `Command.Input`, `Command.List`, `Command.Separator`, `Command.Shortcut`, `Command.Loading` - Use for: A command palette (⌘K), or picking from a long list by typing: jump to a project, run an action. - Don't: Choosing a value for a form field: use `Combobox`. A short list that fits on screen: use `DropdownMenu`. ```svelte Nothing found. goToProject('zest')}>Zest ``` Props of `Command.Root`: - `columns` (`number | null`, default `null`): The number of columns in a grid layout. - `disableInitialScroll` (`boolean`, default `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) => 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` (`string`, default `''`, bindable): Optionally provide or bind to the selected command menu item. - `vimBindings` (`boolean`, default `true`): Set this prop to `false` to disable the option to use ctrl+n/j/p/k (vim style) navigation. Props of `Command.Dialog`: - `columns` (`number | null`, default `null`): The number of columns in a grid layout. - `description` (`string`, default `the Config's `strings.commandPaletteDescription`, else 'Search for a command to run.'`): The palette's description for screen readers. - `disableInitialScroll` (`boolean`, default `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`): A callback that is called when the popover's open state changes. - `onOpenChangeComplete` (`OnChangeFn`): A callback called when the dialog finishes opening/closing animations. - `onStateChange` (`((state: Readonly) => 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` (`boolean`, default `false`, bindable): 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`, default `false`): Show a close button in the corner. - `title` (`string`, default `the Config's `strings.commandPalette`, else 'Command palette'`): The palette's name for screen readers. - `value` (`string`, default `''`, bindable): Optionally provide or bind to the selected command menu item. - `vimBindings` (`boolean`, default `true`): Set this prop to `false` to disable the option to use ctrl+n/j/p/k (vim style) navigation. Props of `Command.Empty`: - `forceMount` (`boolean`): Whether to force mount the group container regardless of filtering logic. Props of `Command.Group`: - `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. Props of `Command.Item`: - `disabled` (`boolean`, default `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. Props of `Command.LinkItem`: - `disabled` (`boolean`, default `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. Props of `Command.Input`: - `value` (`string`, default `''`, bindable): The value of the input element, used to search/filter items. Props of `Command.Separator`: - `forceMount` (`boolean`): Whether to force mount the separator container regardless of filtering logic. Props of `Command.Loading`: - `progress` (`number`): The current progress of the loading state. This is a number between `0` and `100`. Example: Basic Typing filters by value and keywords; arrow keys move, Enter runs. ```svelte
Nothing found. (last = 'Zest')}> Zest (last = 'Worklog')}> Worklog (last = 'New report')} > New report ⌘N (last = 'Settings')}> Settings

Ran: {last}

``` Example: A palette Command.Dialog as a palette, opened with ⌘K or Ctrl+K. ```svelte Nothing found. (open = false)}>Projects (open = false)}>Reports (open = false)}>Invoices ```