shadcn.io is an independent project built on shadcn/ui
Components
Free
Command for Svelte
A command palette for Svelte on Ark UI: a search field that narrows a list of actions as you type, with groups, shortcut hints and a dialog.
On this page9 sections
UI library: Ark UI
Command puts a search field above a list of actions. People type a few letters, the list narrows to the rows that match, and Enter runs the highlighted one. Open it in a dialog on Cmd+K as an app-wide command palette, or keep it inline at the top of a sidebar or a menu.
When the pick is a value a form keeps, such as a country or an assignee, use a Combobox. A short menu with nothing to search reads better as a Dropdown Menu.
Installation
Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.
Focus stays in the search field while the arrow keys move a highlight through the list, and the field points at the highlighted row with aria-activedescendant, so a screen reader reads each row as it's reached. The field has the combobox role and the list is a listbox of options, named "Suggestions". CommandInput takes its accessible name from its placeholder, or "Search" without one. CommandDialogContent gives the dialog a title only screen readers hear, "Command Palette" unless you set title. The icons are decoration, so keep them aria-hidden as the demos do.
KeyAction
Arrow Down
Highlights the next item, and stays on the last one unless you set loopFocus on Command.
Arrow Up
Highlights the previous item, and stays on the first one unless you set loopFocus on Command.
Home
Highlights the first item.
End
Highlights the last item.
Enter
Picks the highlighted item and clears the search field.
EscEscape
In CommandDialog, closes the palette.
Demos
Basic
An Open Menu button opens a dialog with three suggestions, Calendar, Search Emoji and Calculator, under a field that narrows them as you type. A short message takes the rows' place when nothing matches. Start here for a palette over a few actions, or leave out the dialog to keep the list on the page, like the menu at the top.
Shortcuts
Profile, Billing and Settings, each with an icon and a CommandShortcut at the end of the row showing ⌘P, ⌘B or ⌘S. The hint is text, and nothing in this demo listens for those keys. Show hints when the actions already have shortcuts elsewhere in your app, so the palette teaches them, and bind the keys yourself.
Groups
Suggestions and Settings sit under their own headings with a separator between them, an icon on every row and shortcut hints on the settings rows. Each item names its group, groupBy in useListCollection reads that field, and collection.group() returns the sections. Group the commands once they fall into more than one kind, such as places to go and things to do.
Scrollable
Twenty-three commands in five groups, from Navigation and Actions down to Account and Tools, more than the dialog can show at once. The list stops at 18rem and scrolls with its scrollbar hidden, while the search field stays at the top. At this length a few typed letters beat scrolling, and the headings help the people who scroll anyway.
Palette
Cmd+K on a Mac or Ctrl+K elsewhere toggles the palette from anywhere on the page, and a Search button opens it for pointer and touch users. Pages and Actions are grouped, and a footer names the keys for moving, picking and closing. Picking a row writes its name under the button and closes the dialog, which is the wiring an app-wide palette needs.
RTL
The inline menu from the top of the page in Arabic, with dir set to rtl on both Command and CommandInput. Headings, labels, the placeholder and the empty message are translated, the calculator row stays disabled, and the shortcut hints move to the inline end of each row, on the left. Use it to check the filter and the separators in a right-to-left layout.
FAQ
How do I open the Command palette with Cmd+K in Svelte?
Listen for the shortcut on document yourself, because the component binds no keys of its own. In the keydown handler, check that the key is k and that metaKey or ctrlKey is down, call preventDefault() so the browser doesn't act on the keys too, and flip the open state you pass to CommandDialog.
Add the listener when the component mounts and remove it when it unmounts. The Palette demo does exactly this, and keeps a Search button on the page for phones, where there is no shortcut to press.
How do I run an action when a Command item is selected?
Handle onSelect on Command. It fires on every pick, by click or Enter, with the row's value in details.itemValue. The Palette demo uses onValueChange instead, with value held at an empty array so that picking the same row twice still fires, and reads the whole item from details.items.
Navigating works the same way: go to the route in that handler, then close the dialog so the page underneath is what people see.
Should I use a Command or a Combobox?
Use a Command when picking a row does something: it opens a page, runs an action or flips a setting, the way a command palette or a searchable action menu works. The search is a way to reach the action, and nothing needs to remember which row was chosen.
Use a Combobox when the pick is a value that stays in a form field afterwards, like a country or an assignee, and goes out with the form when it's submitted.
How do I change how the Command filters and ranks items?
Ark UI leaves filtering to you: Command shows the collection you pass, and the demos narrow it with useListCollection. Its filter option decides what matches, here contains from useFilter, which ignores case and accents and tests each item's label.
Swap in startsWith from the same hook, or write a function that also reads the item, its third argument, to match on aliases. Items stay in the order you gave them, since nothing is ranked.
How do I load Command results from an API as the user types?
Fetch in onInputValueChange on Command, then put the response in the collection with set from useListCollection, which replaces the items. Leave out the hook's filter option so the server's results show as they come back.
Debounce the request so each keystroke doesn't start a new one. CommandEmpty shows whenever the collection is empty, so render a loading row while the first request is in flight.
Why doesn't pressing a Command shortcut do anything?
CommandShortcut is a label and nothing more. It prints the keys at the end of the row, but no code listens for them, in the palette or anywhere else.
Bind each one yourself with a keydown listener on document, the way the Palette demo binds Cmd+K, and have it call the same function the row runs when it's picked. Keeping both in one place stops a hint from naming keys that do something else.
How do I show a message when no Command results match?
Put a CommandEmpty inside CommandList. It renders only while the collection you pass is empty, which is what your filter produces when nothing matches, and without children it says "No results found." Give it your own words, such as a hint to try another term or a link to the full search.
How do I clear the Command search when the palette closes?
Reset the filter in the dialog's onOpenChange. Closing CommandDialog unmounts the Command, so the field comes back empty, but the collection from useListCollection lives in your component and stays narrowed by the last search.
Call filter("") when details.open is false, as the Palette demo does, and the whole list is there on the next open.
API Reference
Command
<div>data-slot="command"
PropType
inputValue?string
The controlled value of the combobox's input.
defaultInputValue?string
The initial value of the combobox's input when rendered.
Use when you don't need to control the value of the combobox's input.
Whether to allow typing custom values in the input.
alwaysSubmitOnEnter?boolean
Whether to always submit on Enter key press, even if popup is open.
Useful for single-field autocomplete forms where Enter should submit the form.
Default
false
autoFocus?boolean
Whether to autofocus the input on mount.
closeOnSelect?boolean
Whether to close the combobox when an item is selected.
Default
false
composite?boolean
Whether the combobox is a composed with other composite widgets like tabs.
Default
true
defaultHighlightedValue?string | null
The initial highlighted value of the combobox when rendered.
Use when you don't need to control the highlighted value of the combobox.
Type
string | null
dir?"ltr" | "rtl"
The document's text/writing direction.
Type
"ltr" | "rtl"
Default
"ltr"
disabled?boolean
Whether the combobox is disabled.
disableLayer?boolean
Whether to disable registering this a dismissable layer.
form?string
The associate form of the combobox.
hideMode?"display-none" | "activity"
How to hide content when mounted but not present.
- display-none: HTML hidden attribute. Effects stay alive.
- activity: React 19 <Activity mode="hidden">. Effects pause. Requires React 19+.
Type
"display-none" | "activity"
Default
"display-none"
highlightedValue?string | null
The controlled highlighted value of the combobox.
Type
string | null
id?string
The unique identifier of the machine.
ids?object
The ids of the elements in the combobox. Useful for composition.
Defines the auto-completion behavior of the combobox.
- autohighlight: The first focused item is highlighted as the user types
- autocomplete: Navigating the listbox with the arrow keys selects the item and the input is updated Ark default: none.
Type
"autohighlight" | "autocomplete" | "none"
Default
autohighlight
invalid?boolean
Whether the combobox is invalid.
lazyMount?boolean
Whether to enable lazy mounting. Ark default: false.
Default
true
loopFocus?boolean
Whether to loop the keyboard navigation through the items. Ark default: true.
Default
false
multiple?boolean
Whether to allow multiple selection.
**Good to know:** When multiple is true, the selectionBehavior is automatically set to clear.
It is recommended to render the selected items in a separate container.
name?string
The name attribute of the combobox's input. Useful for form submission.
The behavior of the combobox input when an item is selected
- replace: The selected item string is set as the input value
- clear: The input value is cleared
- preserve: The input value is preserved Ark default: replace.
Type
"clear" | "replace" | "preserve"
Default
clear
skipAnimationOnMount?boolean
Whether to allow the initial presence animation.
Default
false
translations?object
Specifies the localized strings that identifies the accessibility elements and their states.
Whether to close the dialog when the escape key is pressed.
Default
true
closeOnInteractOutside?boolean
Whether to close the dialog when the outside is clicked.
Default
true
dir?"ltr" | "rtl"
The document's text/writing direction.
Type
"ltr" | "rtl"
Default
"ltr"
finalFocusEl?() → MaybeElement
Element to receive focus when the dialog is closed.
Returns
MaybeElement
hideMode?"display-none" | "activity"
How to hide content when mounted but not present.
- display-none: HTML hidden attribute. Effects stay alive.
- activity: React 19 <Activity mode="hidden">. Effects pause. Requires React 19+.
Type
"display-none" | "activity"
Default
"display-none"
id?string
The unique identifier of the machine.
ids?object
The ids of the elements in the dialog. Useful for composition.
Render your own element: a snippet that gets the part's props to spread on it.
Type
Snippet<[PropsFn]>
class?string
Merged with the part's classes.
AttributeType
data-empty?string
Present when the content is empty.
data-has-nested?string
Present when another listbox is nested inside it.
data-nested?string
Present when it's nested inside another listbox.
data-placementstring
The placement of the content.
data-side"top" | "right" | "bottom" | "left"
The side of the trigger that the content is positioned on.
Type
"top" | "right" | "bottom" | "left"
data-state"open" | "closed"
"open" or "closed".
Type
"open" | "closed"
CSS variableType
--layer-indexstring
The index of the dismissable in the layer stack.
--nested-layer-countstring
The number of nested comboboxs.
CommandList
data-slot="command-list"
PropType
asChild?Snippet<[PropsFn]>
Render your own element: a snippet that gets the part's props to spread on it.
Type
Snippet<[PropsFn]>
class?string
Merged with the part's classes.
AttributeType
data-invalid?string
Present when invalid is true.
data-readonly?string
Present when readOnly is true.
CommandEmpty
data-slot="command-empty"
PropType
asChild?Snippet<[PropsFn]>
Render your own element: a snippet that gets the part's props to spread on it.
Type
Snippet<[PropsFn]>
class?string
Merged with the part's classes.
AttributeType
data-invalid?string
Present when invalid is true.
data-readonly?string
Present when readOnly is true.
CommandSeparator
data-slot="command-separator"
PropType
class?string
Merged with the part's classes.
AttributeType
data-invalid?string
Present when invalid is true.
data-readonly?string
Present when readOnly is true.
CommandShortcut
data-slot="command-shortcut"
PropType
asChild?Snippet<[PropsFn]>
Render your own element: a snippet that gets the part's props to spread on it.
Type
Snippet<[PropsFn]>
class?string
Merged with the part's classes.
AttributeType
data-invalid?string
Present when invalid is true.
data-readonly?string
Present when readOnly is true.
CommandFooter
<div>data-slot="command-footer"
PropType
class?string
Merged with the part's classes.
CommandRootProvider
<div>data-slot="command"
PropType
valueUseComboboxReturn<T>
What useCommand() returns: the state and API, made outside the component to control it.
Type
UseComboboxReturn<T>
hideMode?"display-none" | "activity"
How to hide content when mounted but not present.
- display-none: HTML hidden attribute. Effects stay alive.
- activity: React 19 <Activity mode="hidden">. Effects pause. Requires React 19+.
Type
"display-none" | "activity"
Default
"display-none"
immediate?boolean
Whether to synchronize the present change immediately or defer it to the next frame.
lazyMount?boolean
Whether to enable lazy mounting. Ark default: false.
Default
true
onEnterComplete?VoidFunction
Function called when the animation ends in the open state.
onExitComplete?VoidFunction
Function called when the animation ends in the closed state.
present?boolean
Whether the node is present (controlled by the user).
skipAnimationOnMount?boolean
Whether to allow the initial presence animation.
Default
false
unmountOnExit?boolean
Whether to unmount on exit. Ark default: false.
Default
true
asChild?Snippet<[PropsFn]>
Render your own element: a snippet that gets the part's props to spread on it.