Combobox
A filterable autocomplete: a combobox input over a listbox popup, rendered from an options array with ranked filtering, group headings, and full keyboard navigation. Focus stays on the input the whole time; the active option is tracked with aria-activedescendant. State is controlled through a @change callback.
Installation
Copy the piece into your app — it compiles with your build and the code is yours:
puzzle add piece combobox
No npm dependencies. Requires the pieces.css tokens merged into your app styles (see Introduction).
Usage
import Combobox from '@/components/ui/Combobox.pzl';
<Combobox options={ frameworks } value={ framework } @change={ setFramework } />// The option element, ARIA, and handlers stay owned by Combobox.
// Declare the full option shape; Puzzle diagnoses shape mismatches in development.
<Combobox options={ people } value={ person } @change={ setPerson }>
<Snippet fits="option" item active selected disabled>
<img class="size-6 rounded-full" src={ item.avatar } alt="" />
<span class="truncate">{ item.name }</span>
</Snippet>
</Combobox>Groups and dividers
Custom filter
The built-in ranker matches case-insensitively, word-prefix before substring. Pass a filter function to override it — return truthy to keep an option. Here the filter also matches each country's two-letter code, so typing us finds United States.
Error state
Please pick a framework
Controlled open
Open state is optional-controlled. Omit open and the combobox owns it; pass it and the parent does, reacting to @show and @hide.
Parent open state: closed
Keyboard
Focus stays on the input; these keys drive the popup:
- Type — re-filters and opens the list, reseating the active option
- Down / Up arrows — open the list, then move the active option (wraps, skips disabled)
- Home / End — jump to the first or last option
- Enter — select the active option and close
- Escape — revert the input to the selected label and close
- Tab — close and move focus on naturally