Skip to content

Combobox

A combobox is a form element that allows the user to select one or more options from a set of choices.

HeadlessUI Combobox Documentation

Import

Terminal window
import { Combobox } from "@aeonkit/react";

Usage

Create an array of anything you want to use as options. For these examples, we’ll use an array of objects with label and value keys.

Terminal window
const cities = [
{
label: "Houston, TX",
value: "houston",
},
{
label: "Austin, TX",
value: "austin",
},
{
label: "Dallas, TX",
value: "dallas",
},
{
label: "San Antonio, TX",
value: "san-antonio",
},
{
label: "Fort Worth, TX",
value: "fort-worth",
},
{
label: "Los Angeles, CA",
value: "los-angeles",
},
{
label: "San Diego, CA",
value: "san-diego",
},
{
label: "San Francisco, CA",
value: "san-francisco",
},
{
label: "San Jose, CA",
value: "san-jose",
},
{
label: "Sacramento, CA",
value: "sacramento",
},
]

Single

Single combobox allows only one item to be selected at a time.

Multiple

Multiple combobox allows multiple items to be selected at a time. Use the multiple prop to enable this feature.

Houston, TX Los Angeles, CA

Styling states

You can style the selected and focused states by using data attributes. For example:

Terminal window
<Combobox.Option
value={city}
className="group flex gap-2 bg-white data-[focus]:bg-blue-100"
>
<LuCheck className="invisible size-5 group-data-[selected]:visible" />
{city.label}
</Combobox.Option>

Read more about styling states. Note: You can not style via render props at this time.

Props

API Interface: ComboboxProps