Fine-tune light, shadows, borders, neumorphic
Light and shadows
Borders
Neumorphic
Forms Form-associated

Combobox <pm-combobox>

Combobox / autocomplete: a searchable select.

Full screen

Props

<script type="module"> import '@prismora/css'; import '@prismora/elements/combobox'; </script> <pm-combobox label="Country" placeholder="Search countries…" clearable> <optgroup label="Europe"> <option value="de">Germany</option> <option value="fr">France</option> <option value="es">Spain</option> </optgroup> <optgroup label="Asia"> <option value="in">India</option> <option value="jp">Japan</option> </optgroup> </pm-combobox> <pm-combobox label="Labels" multiple creatable value="bug,ui" placeholder="Add label…"> <option value="bug">Bug</option> <option value="ui">UI</option> <option value="perf">Performance</option> <option value="docs">Docs</option> </pm-combobox>

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.

Disabled
Read-only
Loading
Required
Error
With a hint

Overview

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

AttributeTypeDefaultDescription
multiplebooleanfalseAllow more than one value.
placeholderstring—Hint text shown while empty (not a replacement for label).
creatablebooleanfalseOffer "Create …" for queries that match nothing.
clearablebooleanfalseShow a button that clears the value.
filter'contains' | 'starts-with' | 'none'containscontains (default), starts-with, or none (you filter, e.g. server-side on pm-search).
loadingbooleanfalseShow a loading row (async search).
empty-text
prop: emptyText
stringNo resultsText shown when there is nothing to list.
srcstring—Search URL; {query} is replaced with the URL-encoded text (e.g. /api/users?q={query}). Response: JSON.
options-path
prop: optionsPath
string—Where the list is in the response, as a dotted path (e.g. data.items); empty = the response itself.
value-key
prop: valueKey
string—Item field for the value (default value, then id).
label-key
prop: labelKey
string—Item field for the label (default label, then name, then title).
description-key
prop: descriptionKey
string—Item field for the secondary text (default description).
group-key
prop: groupKey
string—Item field for the group heading (default group).
debouncenumber250Milliseconds to wait after typing before searching the server.
min-chars
prop: minChars
number1Characters needed before searching the server (0 = load as soon as it opens).
namestring—Form field name: the value is submitted under it.
valuestring—Current value (submitted with the form).
labelstring—Visible label (required for accessibility; use hide-label to visually hide it).
hintstring—Help text under the field, linked to it for screen readers.
errorstring—Custom error message. Setting it marks the control invalid.
size'xs' | 'sm' | 'md' | 'lg' | 'xl'—Control size.
requiredbooleanfalseThe form cannot be submitted until this has a value.
disabledbooleanfalseNot interactive and not submitted.
readonlybooleanfalseFocusable and submitted, but not editable.
hide-label
prop: hideLabel
booleanfalseHide 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

EventReact / Svelte propDescription
pm-searchonPmSearchThe query changed.
pm-createonPmCreateA new entry was created (with creatable).
pm-loadonPmLoadServer results arrived.
pm-load-erroronPmLoadErrorA server search failed.
pm-changeonPmChangeWhen the value is committed.

Methods

search(), checkValidity(), reportValidity(), validate(), focus()