Combobox <pm-combobox>
Combobox / autocomplete: a searchable select.
Sizes
Set with the size attribute; controls keep touch-sized targets on phones.
size="xs"size="sm"size="md"size="lg"size="xl"States
Each state is one attribute.
DisabledRead-onlyLoadingRequiredErrorWith a hintOverview
Single or multiple (selections become tags; value joins them with commas, values lists them), creatable entries, clearable and grouped options. Options come from child <option> / <optgroup> elements or the options property. Keyboard: ↓/↑ move, Enter selects, Esc closes, Backspace removes the last tag.
Server-side search: set src to a URL template (src="/api/users?q={query}") and say where the list is in the JSON (options-path="data") and which fields to use (value-key="id" label-key="name"), or set the loader property to your own async (query, { signal }) => items and optionally mapOption to format each item. Requests are debounced (debounce, default 250 ms), start after min-chars characters, cancel when superseded, and show loading, empty and error (with Retry) states. Selected values keep their labels across searches. Without either, you can still filter yourself: filter="none", listen for pm-search and set options.
Attributes
| Attribute | Type | Default | Description |
|---|---|---|---|
multiple | boolean | false | Allow more than one value. |
placeholder | string | — | Hint text shown while empty (not a replacement for label). |
creatable | boolean | false | Offer "Create …" for queries that match nothing. |
clearable | boolean | false | Show a button that clears the value. |
filter | 'contains' | 'starts-with' | 'none' | contains | contains (default), starts-with, or none (you filter, e.g. server-side on pm-search). |
loading | boolean | false | Show a loading row (async search). |
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 (e.g. /api/users?q={query}). Response: JSON. |
options-pathprop: optionsPath | string | — | Where the list is in the response, as a dotted path (e.g. data.items); 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). |
description-keyprop: descriptionKey | string | — | Item field for the secondary text (default description). |
group-keyprop: groupKey | string | — | Item field for the group heading (default group). |
debounce | number | 250 | Milliseconds to wait after typing before searching the server. |
min-charsprop: minChars | number | 1 | Characters needed before searching the server (0 = load as soon as it opens). |
name | string | — | Form field name: the value is submitted under it. |
value | string | — | Current value (submitted with the form). |
label | string | — | Visible label (required for accessibility; use hide-label to visually hide it). |
hint | string | — | Help text under the field, linked to it for screen readers. |
error | string | — | Custom error message. Setting it marks the control invalid. |
size | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | — | Control size. |
required | boolean | false | The form cannot be submitted until this has a value. |
disabled | boolean | false | Not interactive and not submitted. |
readonly | boolean | false | Focusable and submitted, but not editable. |
hide-labelprop: hideLabel | boolean | false | Hide the label visually; it stays the accessible name. |
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-search | onPmSearch | The query changed. |
pm-create | onPmCreate | A new entry was created (with creatable). |
pm-load | onPmLoad | Server results arrived. |
pm-load-error | onPmLoadError | A server search failed. |
pm-change | onPmChange | When the value is committed. |
Methods
search(), checkValidity(), reportValidity(), validate(), focus()