CSS-only Tailwind CSS combobox with live search filtering and accessible dropdown list. Keyboard navigation, color variants. WCAG AA accessible, works with Django, HTMX, Laravel, React, and any stack.
Combobox combine une saisie de texte avec une liste déroulante. Utilisez le composant input pour le champ : les variantes de taille, de couleur et d'état proviennent de là. Les utilitaires combobox-* gèrent uniquement la liste déroulante, les éléments et l'état ouvert.
CSS uniquement, aucun JavaScript requis. WCAG AA accessible et indépendant du framework – fonctionne avec Django, HTMX, Laravel, React et n'importe quelle pile.
Classe
Taper
Description
combobox-list
Base
Conteneur de liste déroulante pour les options de liste déroulante
combobox-item
Modificateur
Option individuelle dans la liste déroulante
combobox-open
Modificateur
Affiche la liste déroulante lorsqu'elle est appliquée au wrapper
combobox-primary
Couleur
Primary theme color highlight for items
combobox-secondary
Couleur
Secondary theme color highlight for items
combobox-accent
Couleur
Accent theme color highlight for items
combobox-info
Couleur
Info semantic color highlight
combobox-success
Couleur
Success semantic color highlight
combobox-warning
Couleur
Warning semantic color highlight
combobox-error
Couleur
Error semantic color highlight
Utilisation de base
Wrap an input and a combobox-list in a relative container. Add combobox-open to the wrapper to show the list — toggle it via JS or :focus-within.
React
Vue
Angular
Svelte
123456789
<divclass="relative w-64 combobox-open"><inputtype="text"class="input w-full"placeholder="Search or select..."><ulclass="combobox-list"><liclass="combobox-item">React</li><liclass="combobox-item combobox-item-active">Vue</li><liclass="combobox-item">Angular</li><liclass="combobox-item">Svelte</li></ul></div>
1 2 3 4 5 6 7 8 91011121314151617
import{useCombobox}from'frutjam/react'constframeworks=['React','Vue','Angular','Svelte']exportdefaultfunctionComboboxDemo(){constcombo=useCombobox({items:frameworks})return(<div{...combo.containerProps}className="relative w-64"><input{...combo.inputProps}className="input w-full"placeholder="Search or select..."/><ulclassName="combobox-list"role="listbox">{combo.filtered.map((item,i)=>(<likey={item}{...combo.optionProps(item,i)}className="combobox-item">{item}</li>))}</ul></div>)}
Open on Focus
Use focus-within:combobox-open on the wrapper to open the list when the input is focused — no JavaScript needed.
React
Vue
Angular
Svelte
html
123456789
<divclass="relative w-64 focus-within:combobox-open"><inputtype="text"class="input w-full"placeholder="Focus to open..."><ulclass="combobox-list"><liclass="combobox-item">React</li><liclass="combobox-item">Vue</li><liclass="combobox-item">Angular</li><liclass="combobox-item">Svelte</li></ul></div>
Sizes
Use input-sm, input-lg, etc. on the input field. The dropdown adapts naturally.
Use createCombobox from frutjam/js or useCombobox from frutjam/react to get filtering, keyboard navigation (↑ ↓ Enter Escape), and full aria-* wiring out of the box. Listen for the fj:select event to handle selection.