Command <pm-command>
Command palette (⌘K / Ctrl+K): a modal search over actions and pages, grouped, fuzzy-matched, keyboard driven.
Overview
Items come from child <pm-command-item> elements or the items property. Open with the shortcut, el.show(), or an invoker: <pm-button commandfor="cmd" command="--open">.
Server search: set src (src="/api/search?q={query}", with items-path, value-key, label-key, group-key, href-key) or the loader property (async (query, { signal }) => items, mapItem to format). Local commands still match instantly; server results follow under their own group (results-group), debounced, with loading and error (Retry) states.
Attributes
| Attribute | Type | Default | Description |
|---|---|---|---|
open | boolean | false | Whether it is open. Set to open or close it; changes when the user opens or closes it. |
placeholder | string | Type a command or search… | Hint text shown while empty (not a replacement for label). |
label | string | Command palette | Accessible name (and visible label where the component shows one). |
shortcut | string | mod+k | Global shortcut ("mod+k" by default; "mod" is ⌘ on Apple, Ctrl elsewhere). Set to "" to disable. |
empty-textprop: emptyText | string | No results | Text shown when there is nothing to list. |
src | string | — | Search URL; {query} is replaced with the URL-encoded text. Response: JSON. |
items-pathprop: itemsPath | string | — | Where the list is in the response (dotted path; empty = the response itself). |
value-keyprop: valueKey | string | — | Item field for the value (default value, then id). |
label-keyprop: labelKey | string | — | Item field for the label (default label, then name, then title). |
group-keyprop: groupKey | string | — | Item field for the group heading (default: results-group). |
href-keyprop: hrefKey | string | — | Item field for a link to open (default href, then url). |
results-groupprop: resultsGroup | string | Results | Group heading for server results without their own group. |
debounce | number | 200 | Milliseconds to wait after typing before searching the server. |
min-charsprop: minChars | number | 1 | Characters needed before searching the server. |
Also accepts the contextual attributes tone, surface, radius, density, motion, elevation. They are inherited from ancestors' data-* attributes.
Events
| Event | React / Svelte prop | Description |
|---|---|---|
pm-select | onPmSelect | An item was chosen. Cancel it to keep an item with href from opening. |
pm-open | onPmOpen | Opened. |
pm-close | onPmClose | Closed. |
pm-load | onPmLoad | Server results arrived. |
pm-load-error | onPmLoadError | A server search failed. |
Methods
show(), hide(), toggle()
<pm-command-item>
An action in a command palette (data only, not rendered itself).
Attributes
| Attribute | Type | Default | Description |
|---|---|---|---|
value | string | — | Value reported in pm-select (defaults to the text). |
group | string | — | Group heading. |
keywords | string | — | Extra search words, space or comma separated. |
shortcut | string | — | Shortcut hint shown on the right, e.g. "Ctrl N". |
href | string | — | Navigate here when chosen. |
disabled | boolean | — | Not interactive (and not submitted, for form controls). |