Command
Command menu for search and quick actions.
Installation
pnpm add @heyramzi/ui bits-uiUsage
import * as Command from "@heyramzi/ui/shadcn/command";<Command.Root>
<Command.Input placeholder="Type a command or search..." />
<Command.List>
<Command.Empty>No results found.</Command.Empty>
<Command.Group heading="Suggestions">
<Command.Item>Calendar</Command.Item>
<Command.Item>Search emoji</Command.Item>
</Command.Group>
<Command.Separator />
<Command.Group heading="Settings">
<Command.Item>
Profile
<Command.Shortcut>⌘P</Command.Shortcut>
</Command.Item>
</Command.Group>
</Command.List>
</Command.Root>Keyboard and accessibility
| Key | Does |
|---|---|
| Arrow Down Ctrl N Ctrl J | Moves to the next item. |
| Arrow Up Ctrl P Ctrl K | Moves to the previous item. |
| Home | Moves to the first item. |
| End | Moves to the last item. |
| Enter | Runs the highlighted item. |
- Focus stays in the search box while the arrow keys move a highlight through the list.
- Typing filters the list. Command.Empty shows when nothing matches.
- The highlight stops at the ends unless loop is set.
- Command.Dialog adds a hidden title, and works like a dialog: Esc closes it.
API reference
Command.Root
apibindableCommandRootApi | null- Default
null refbindableHTMLElement | null- Default
null valuebindablestring- Default
"" classstring...rest- Every prop of
Command.Rootfrombits-ui
| Prop | Type | Default |
|---|---|---|
api bindable | CommandRootApi | null | null |
ref bindable | HTMLElement | null | null |
value bindable | string | "" |
class | string | |
...rest | Every prop of Command.Root from bits-ui | |
Command.Input
wrapperClassstring- Classes for the row that holds the glyph, the field and `trailing`.
size"default" | "lg"- Default
"default" - `lg` is the standalone search header; `default` is a combobox popover.
trailingSnippet- Right-aligned affordances: a dismiss hint, a close button, a scope chip.
refbindableHTMLElement | null- Default
null classstringvaluebindablestring- Default
"" ...rest- Every prop of
Command.Inputfrombits-uiexceptsize
| Prop | Type | Default |
|---|---|---|
wrapperClass Classes for the row that holds the glyph, the field and `trailing`. | string | |
size `lg` is the standalone search header; `default` is a combobox popover. | "default" | "lg" | "default" |
trailing Right-aligned affordances: a dismiss hint, a close button, a scope chip. | Snippet | |
ref bindable | HTMLElement | null | null |
class | string | |
value bindable | string | "" |
...rest | Every prop of Command.Input from bits-ui except size | |
Command.List
refbindableHTMLElement | null- Default
null classstringchildrenSnippet...rest- Every prop of
Command.Listfrombits-ui
| Prop | Type | Default |
|---|---|---|
ref bindable | HTMLElement | null | null |
class | string | |
children | Snippet | |
...rest | Every prop of Command.List from bits-ui | |
Command.Empty
refbindableHTMLElement | null- Default
null classstring...rest- Every prop of
Command.Emptyfrombits-ui
| Prop | Type | Default |
|---|---|---|
ref bindable | HTMLElement | null | null |
class | string | |
...rest | Every prop of Command.Empty from bits-ui | |
Command.Group
headingstringrefbindableHTMLElement | null- Default
null classstringchildrenSnippetvalueCommand.Group...rest- Every prop of
Command.Groupfrombits-ui
| Prop | Type | Default |
|---|---|---|
heading | string | |
ref bindable | HTMLElement | null | null |
class | string | |
children | Snippet | |
value | Command.Group | |
...rest | Every prop of Command.Group from bits-ui | |
Command.Item
refbindableHTMLElement | null- Default
null classstringchildrenSnippet...rest- Every prop of
Command.Itemfrombits-ui
| Prop | Type | Default |
|---|---|---|
ref bindable | HTMLElement | null | null |
class | string | |
children | Snippet | |
...rest | Every prop of Command.Item from bits-ui | |
Command.Separator
refbindableHTMLElement | null- Default
null classstring...rest- Every prop of
Command.Separatorfrombits-ui
| Prop | Type | Default |
|---|---|---|
ref bindable | HTMLElement | null | null |
class | string | |
...rest | Every prop of Command.Separator from bits-ui | |
Command.Shortcut
refbindableHTMLElement | null- Default
null classstringchildrenSnippet...rest- Every prop of
HTMLAttributes<HTMLElement>fromsvelte/elements
| Prop | Type | Default |
|---|---|---|
ref bindable | HTMLElement | null | null |
class | string | |
children | Snippet | |
...rest | Every prop of HTMLAttributes<HTMLElement> from svelte/elements | |
Command.Dialog
portalPropsDialogPrimitive.PortalPropschildrenrequiredSnippettitlestring- Default
"Command Palette" descriptionstring- Default
"Search for a command to run..." showCloseButtonboolean- Default
false closeLabelstring- Default
"Close" - What a screen reader calls the close button, in the app's language.
classstringopenbindableboolean- Default
false refbindableHTMLElement | null- Default
null valuebindablestring- Default
"" ...rest- Every prop of
Dialog.Rootfrombits-uiexceptchild, children ...rest- Every prop of
Command.Rootfrombits-uiexceptchild, children
| Prop | Type | Default |
|---|---|---|
portalProps | DialogPrimitive.PortalProps | |
children required | Snippet | |
title | string | "Command Palette" |
description | string | "Search for a command to run..." |
showCloseButton | boolean | false |
closeLabel What a screen reader calls the close button, in the app's language. | string | "Close" |
class | string | |
open bindable | boolean | false |
ref bindable | HTMLElement | null | null |
value bindable | string | "" |
...rest | Every prop of Dialog.Root from bits-ui except child, children | |
...rest | Every prop of Command.Root from bits-ui except child, children | |
Command.LinkItem
refbindableHTMLElement | null- Default
null classstring...rest- Every prop of
Command.LinkItemfrombits-ui
| Prop | Type | Default |
|---|---|---|
ref bindable | HTMLElement | null | null |
class | string | |
...rest | Every prop of Command.LinkItem from bits-ui | |
Command.Loading
refbindableHTMLElement | null- Default
null ...rest- Every prop of
Command.Loadingfrombits-ui
| Prop | Type | Default |
|---|---|---|
ref bindable | HTMLElement | null | null |
...rest | Every prop of Command.Loading from bits-ui | |