Combobox

An editable single-key chooser. Suggestions do not become selections until accepted.
Download runnable sandbox
import { createSignal } from "solid-js";
import { Combobox } from "@wsagency/radix2solid-primitives";
import styles from "./styles.module.css";
const destinations = [
{ value: "paris", label: "Paris" },
{ value: "prague", label: "Prague" },
{ value: "porto", label: "Porto", disabled: true },
];
export default function ComboboxDemo() {
const [value, setValue] = createSignal<string | null>(null);
const [query, setQuery] = createSignal("");
const [accept, setAccept] = createSignal(true);
const [keepParis, setKeepParis] = createSignal(true);
const [preventReset, setPreventReset] = createSignal(false);
const [submitted, setSubmitted] = createSignal("Not submitted");
const [submissions, setSubmissions] = createSignal(0);
let form!: HTMLFormElement;
return <form ref={form} class={styles.Demo} aria-label="Destination booking" onReset={event => { if (preventReset()) event.preventDefault(); }} onSubmit={event => { event.preventDefault(); setSubmitted(String(new FormData(event.currentTarget).get("destination") ?? "No successful field")); setSubmissions(count => count + 1); }}>
<Combobox.Root items={destinations.filter(item => keepParis() || item.value !== "paris")} value={value()} onValueChange={next => { if (accept()) setValue(next); }} query={query()} onQueryChange={setQuery} name="destination" required>
<div class={styles.Controls}>
<Combobox.Input class={styles.Input} aria-label="Destination" placeholder="Choose a destination" />
<Combobox.Trigger class={styles.Button} aria-label="Show destinations">Show</Combobox.Trigger>
<Combobox.Clear class={styles.Button} aria-label="Clear destination">Clear</Combobox.Clear>
</div>
<Combobox.Portal>
<Combobox.Content class={styles.Content} sideOffset={5}>
<Combobox.List aria-label="Destinations">
<Combobox.Group>
<Combobox.Label class={styles.Label}>Europe</Combobox.Label>
{destinations.filter(item => keepParis() || item.value !== "paris").map(item =>
<Combobox.Item class={styles.Item} value={item.value}>
<Combobox.ItemText>{item.label}</Combobox.ItemText>
<Combobox.ItemIndicator> ✓</Combobox.ItemIndicator>
</Combobox.Item>)}
</Combobox.Group>
</Combobox.List>
<Combobox.Empty class={styles.Label}>No destinations match.</Combobox.Empty>
</Combobox.Content>
</Combobox.Portal>
</Combobox.Root>
<div class={styles.Controls}>
<button class={styles.Button} type="submit">Book destination</button>
<button class={styles.Button} type="button" onClick={() => form.requestSubmit()}>Request booking</button>
<button class={styles.Button} type="reset">Reset destination</button>
</div>
<label><input type="checkbox" checked={accept()} onChange={event => setAccept(event.currentTarget.checked)} /> Accept value proposals</label>
<label><input type="checkbox" checked={keepParis()} onChange={event => setKeepParis(event.currentTarget.checked)} /> Keep Paris in data</label>
<label><input type="checkbox" checked={preventReset()} onChange={event => setPreventReset(event.currentTarget.checked)} /> Prevent reset</label>
<div role="status" aria-label="Accepted destination">Key: {value() ?? "none"}</div>
<div role="status" aria-label="Destination query">Query: {query() || "empty"}</div>
<div role="status" aria-label="Submitted destination">Submitted: {submitted()}; count: {submissions()}</div>
</form>;
}

Introduced in published 0.1.0-rc.3 and included in the current Primitives 0.1.0-rc.4 release, this native Solid component is not part of historical rc.2. Primitives is published on npm as 0.1.0-rc.4; use the exact-version installation instructions. The Themes recipe adds presentation without a second filtering or focus engine.

Imports and anatomy

import { Combobox } from "@wsagency/radix2solid-primitives";
// Alternatively: import * as Combobox from "@wsagency/radix2solid-primitives/combobox";
export default () => <Combobox.Root items={[{ value: "paris", label: "Paris" }]} name="destination">
<Combobox.Input aria-label="Destination" />
<Combobox.Trigger aria-label="Show destinations">Show</Combobox.Trigger>
<Combobox.Clear aria-label="Clear destination">Clear</Combobox.Clear>
<Combobox.Portal>
<Combobox.Content>
<Combobox.List aria-label="Destinations">
<Combobox.Group>
<Combobox.Label>Europe</Combobox.Label>
<Combobox.Item value="paris">
<Combobox.ItemText>Paris</Combobox.ItemText>
<Combobox.ItemIndicator>Selected</Combobox.ItemIndicator>
</Combobox.Item>
</Combobox.Group>
</Combobox.List>
<Combobox.Empty>No destinations match.</Combobox.Empty>
</Combobox.Content>
</Combobox.Portal>
</Combobox.Root>;

API reference

Root

PropType / defaultMeaning
itemsreadonly ComboboxItem[], requiredComplete data records, including selected records whose rows are filtered out.
value, defaultValuestring | null, default nullAccepted key, independently controlled from the query.
onValueChange(value: string | null) => voidProposal, not confirmation of parent acceptance.
query, defaultQuerystringVisible text; absent default derives from the initial accepted item's label, otherwise empty.
onQueryChange(query: string) => voidQuery proposal. A controlled query stays parent-authoritative.
open, defaultOpenboolean, default falseSuggestion popup state.
onOpenChange(open: boolean) => voidOpen-state proposal.
filter(item, query) => boolean or falseDefault is case-insensitive label substring matching against trimmed query, preserving order. false disables it.
disabled, readOnly, requiredboolean, default falseInteraction and form participation; see the read-only validation caveat below.
name, formstringSuccessful key field name and optional external form ID. Root owns both associations.
dir"ltr" | "rtl"Text direction.

ComboboxItem is { value: string; label: string; disabled?: boolean }. Keys must be nonempty, unique and stable; invalid keys are configuration errors. Plain-text labels may repeat. Data supplies the server-rendered selected label: rich ItemText children never redefine it.

Parts

PartResponsibility
InputNative text input, role="combobox", aria-autocomplete="list"; supply a label or accessible name. Forward descriptions and input attributes here, but leave submission name/form to Root.
TriggerOptional named type="button", excluded from tab sequence; toggles without taking input focus.
PortalNative portal server/client lifecycle, not a promise of server-rendered popup options.
ContentNonmodal layer anchored to Input, with existing Popper positioning props such as sideOffset, and explicit labels/descriptions.
ListRoot-owned listbox ID containing rendered options/groups.
ItemRequired value matching Root data. Root supplies label, matching and disabled state. Accepts consumer events/ref/target-factory asChild.
ItemTextLabel presentation only.
ItemIndicatorCommitted-selection presentation, distinct from the active suggestion.
Group, LabelAccessible option grouping.
EmptyNon-option status when no matching options are rendered. Place beside List inside Content, never inside the listbox.
ClearOptional named button requesting null key, empty query and close, then input focus. Disabled/read-only prevents mutation.

Query is not a value

Typing changes the query and opens suggestions, not the accepted key. Filtering never selects. Trigger shows current-query matches without accepting the first result. Enter on an active option requests its key and label and closes; the same Enter cannot submit the surrounding form. Pointer activation uses the same commitment path. Enter without an active option is a normal submission attempt, subject to validity.

Escape and blur leaving the whole input/popup request the accepted label and close; neither accepts an active suggestion. Clearing text over a selected key remains an unresolved draft. Use Clear to request null explicitly.

All three controlled channels remain authoritative. A parent may reject key, text or open proposals independently. A rejected key paired with an accepted query stays invalid: callbacks are not proof that the new key was accepted. Accepted programmatic/asynchronous keys request their data label; controlled query can refuse reconciliation. No-op proposals are suppressed.

Removing or disabling the accepted record requests null once per transition, never a neighboring value. If the parent refuses, that key remains unresolved and cannot submit. The last known label may remain as a draft. An initially unknown key has no derived label. Keep the selected record in Root data when only filtering its row.

Native forms

A resolved field is either null plus empty text, or an existing enabled key whose label exactly equals the visible query. Only the latter produces a successful named field. Unmatched text, a removed/disabled key, and an empty draft over a nonnull key omit the successful field even in direct FormData or validation-bypassing form.submit().

The visible input is the focusable validation target. Ordinary submit and requestSubmit() reject unresolved text and required null selection, with consistent aria-invalid. The visible text is never submitted as the key. Client validation is not server authorization.

Set Root form for an external form: it associates both validation input and successful field. Conflicting Input name/form does not establish a second owner. Native input/change and accepted-key changes do not double-dispatch change events.

Reset restores captured initial key/query, closes and clears active suggestion. Controlled reset requests initial state and reflects accepted props if the parent refuses. Preventing reset leaves state alone. A removed initial key is invalid, not replaced automatically.

Disabled fields do not interact or submit. Read-only fields remain focusable/copyable and submit a resolved key, but cannot edit/open/clear/select. Native read-only inputs do not participate in constraint validation: required does not guarantee validation in that mode. Unresolved keys still never submit.

Keyboard, accessibility and server rendering

Input retains DOM focus. Up/Down activate enabled visible options without wrapping; opening Down starts at the first, Up at the last. aria-activedescendant only names a mounted visible option. aria-selected represents the active suggestion, while the item state/indicator represents commitment. Reorder/removal reconciles against visible DOM order.

Tab stays native; options/Trigger are not extra tab stops. Home/End, Left/Right, Ctrl/Meta editing and IME composition remain input editing, including RTL. Composition Enter does not commit. Content is nonmodal: no Select-style focus trap and no automatic option focus. Active scrolling does not move input focus; touch scrolling must remain possible.

Combobox.Input defaults the native HTML autocomplete attribute to "off" so browser form-history suggestions do not compete with the custom list or intercept its Enter key. This is separate from aria-autocomplete="list", which describes the custom suggestions to assistive technology. Consumers may override HTML autocomplete, including through a target factory; doing so can re-enable competing browser history behavior. Keep the default for this custom-list recipe.

SSR renders the selected label from data, deterministic IDs, initial invalid state and correct successful-field participation without measurements. Browser custom validity begins during hydration, not before JavaScript; portal options follow the native portal lifecycle. Hydration preserves the input and text.

No freeform keys, multiple selection, tokens, virtualization, asynchronous loader or fuzzy-search engine are included. Use Select for noneditable choice and Command for actions. DOM/browser checks are not a blanket screen-reader certification.

Native source