intro

Combobox

A highly interactive organism that marries a TextInput with an OptionGroup-like dropdown.

Combobox

The Combobox component combines a TextInput with an OptionGroup dropdown, allowing users to filter and select from large lists of options efficiently. It adheres to the Curva & Concreto doctrine by relying on native input forms and strict popover lists.

Basic Combobox

function helper($$renderer) { $$renderer.push(`<p>Start typing to filter the ${$.escape(states.length)} available states.</p>`); }

Current Value: None selected

Validation State

function error($$renderer) { $$renderer.push(`<p>This state is not currently serviced. Please select another.</p>`); }

Sizes

Disabled State

function helper($$renderer) { $$renderer.push(`<p>This selection cannot be changed.</p>`); }

Usage

The Combobox is designed to be composed within a FormField component. It automatically inherits the id, aria-describedby for error/helper linking, and invalid state via context.

<script>
import { FormField, Combobox } from 'cobogo';
let stateValue = $state('');
const states = [
{ value: 'sp', label: 'São Paulo' },
{ value: 'rj', label: 'Rio de Janeiro' },
{ value: 'mg', label: 'Minas Gerais' },
// ...
];
</script>
<FormField id="state-select" label="Select a State">
<Combobox options={states} bind:value={stateValue} placeholder="Type to filter..." />
{#snippet helper()}
<p>Start typing to filter available states.</p>
{/snippet}
</FormField>

Props

PropTypeDefaultDescription
valuestring''The bindable selected value matching an option’s value.
optionsArray<{value: string, label: string}>[]The array of available options to filter and select from.
placeholderstring''Placeholder text for the input when empty.
disabledbooleanfalseDisables the entire combobox interaction.
invalidbooleanfalseForces the invalid (error) state. Usually inherited from FormField.
size'sm' | 'md' | 'lg''md'The size variant of the combobox.
...restany-Standard HTML input attributes forwarded to the underlying input.

Variants

Sizes

The Combobox component supports three sizes: sm, md, and lg, matching the TextInput atom.

<Combobox size="sm" options={opts} />
<Combobox size="md" options={opts} />
<Combobox size="lg" options={opts} />

Invalid State

The invalid state maps the background color to var(--vermelho-soft) and changes the borders and focus outlines to var(--vermelho).

<FormField id="state-invalid" label="State" invalid>
<Combobox options={states} />
{#snippet error()}
<p>Please select a valid option.</p>
{/snippet}
</FormField>

Accessibility

  • The component uses role="combobox" and role="listbox" appropriately.
  • Keyboard navigation is fully supported (ArrowUp, ArrowDown, Enter to select, Escape to close).
  • Focus is managed properly: returns to input on selection, active descendant links visual focus to screen readers.
  • Inherits aria-describedby directly from the FormField wrapper.
  • Respects prefers-reduced-motion for interaction animations like chevron rotation.