// preview in
saved for every page

Combobox

A text input that filters a list as you type. Use it when there are too many options to scroll, or when people know the name of what they want.

Built on Base UIPattern WAI-ARIA ComboboxClient componentSource ↗

Installation

Set up Camaleo once (Installation), then import the parts you need, plus ComboboxEmpty for the no-results message. The skin you load styles the input and the popup.

import { Combobox, ComboboxInput, ComboboxContent, ComboboxList, ComboboxItem } from "@camaleo/react";

Anatomy

Combobox holds the items and the value; ComboboxInput is the text field with its clear and open buttons; the content is a popup rendered in a portal. Every part has a data-slot you can target from CSS.

Curitiba✕⌄
[data-slot="combobox-input-group"][data-slot="combobox-clear"] · [data-slot="combobox-trigger"][data-slot="combobox-input"]

Examples

Every example is a real file you can copy. They all wear the skin, mode and brand from the bar above.

minimal · light · #3fa34d

Empty state

Type a name that isn't there. ComboboxEmpty only shows when nothing matches, so use it to say what to do next, not just "No results".

Objects as items

Store the code, show the name: itemToStringLabel fills the input, itemToStringValue goes to the form, isItemEqualToValue compares them.

Assigned to: Camila Rocha

Controlled

Pick someone. With value and onValueChange the rest of the screen can follow the choice as it happens.

Custom filter

Type "gru" or "galeao". A filter function can match codes, nicknames or text without accents, whatever people actually type.

Enter picks the first match

autoHighlight highlights the first result as you type, so a short query and Enter is enough for tags and labels.

Named buttons

The clear and open buttons are icons. Translate their names with clearLabel and triggerLabel, and make them specific to the field.

Pick a city from the list to see delivery dates.

Required, with an error

Inside a Field, the label names the input and FieldError is read with it; tell people to pick from the list, since free text won't be accepted.

In context

A combobox is usually one field among several. These are whole pieces of UI you can copy, in the skin you picked.

Checkout times out on slow 3G

#482 · opened Nov 3 by Rafael

Assign an issueCard · Field · Combobox · Select · Button
Delivery estimate
Delivery estimateFieldset · Field · Combobox · Input · Button

Date and time

Time zone settingCard · Switch · Field · Combobox

Guidelines

DoLong lists people can name.

Nobody wants to scroll through 27 state capitals; typing "flo" is faster.

Don’tSearch for three options.

Typing is extra work when everything fits on screen; use a Select or radios.

Type a city in Brazil; we deliver to 4,812 of them.

DoSay what to type.

A label, an example in the placeholder and a hint about what is covered.

Don’tJust “Search…”.

Search what? With no visible label, people guess the scope and the format.

Props

PropTypeDefaultDescription
clearLabelstring"Clear"Accessible name of the clear button (translatable).
triggerLabelstring"Show options"Accessible name of the button that opens the list (translatable).
renderReactElement | (props, state) => ReactElement—Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.
disabledbooleanfalseWhether the component should ignore user interaction.

These are the props of ComboboxInput; other input attributes like placeholder pass through. Combobox takes Base UI's root props: items, value, defaultValue, onValueChange, inputValue / onInputValueChange, filter, itemToStringLabel, itemToStringValue, isItemEqualToValue, autoHighlight, limit, multiple, disabled, required and name. ComboboxList takes a function of each item; ComboboxItem takes value and disabled.

Styling hooks

Restyle it without forking: target the attributes, or set the tokens on a parent, a skin or the combobox itself.

Attributes

data-slot"combobox-input-group" · "combobox-input" · "combobox-clear" · "combobox-trigger" · "combobox-positioner" · "combobox-popup" · "combobox-list" · "combobox-item" · "combobox-empty"
data-popup-openon the input and trigger while the list is open
data-highlightedon the item under the keyboard or pointer
data-selectedon the chosen item
data-disabledon a disabled input or item
data-invalidon the input inside an invalid Field

Tokens it reads

Color

--cml-border--cml-border-control--cml-danger--cml-fg--cml-fg-muted--cml-field-bg--cml-field-border-sides--cml-field-shadow--cml-focus-offset--cml-focus-ring--cml-focus-width--cml-item-highlight-fg--cml-item-highlight-shadow--cml-popover-bg--cml-popover-border--cml-shadow-popover--cml-surface-raised

Shape & size

--cml-border-width--cml-field-border-width--cml-field-height--cml-field-padding--cml-font-size-field--cml-gap--cml-item-height--cml-item-padding--cml-popover-border-width--cml-popover-padding--cml-radius-control--cml-radius-field--cml-radius-item--cml-radius-popover

Type & motion

--cml-duration-fast--cml-ease-standard--cml-font-field--cml-motion-scale

This component only

--cml-corner-shape--cml-disabled-opacity--cml-item-divider--cml-item-highlight--cml-placeholder-style

Accessibility

TypingFilters the list and opens it.
↓ / ↑Opens the list, then moves the highlight; focus stays in the input.
EnterPicks the highlighted item and closes the list.
EscCloses the list and keeps what you typed.
TabLeaves the field, closing the list.
Was this page helpful? · Edit this page on GitHub