combobox

onChange called 0 time(s)

Apple
Banana
Cherry
Mango
Orange
import { combobox, lucide } from '@markless/ui';export default function ComboboxBasic() @{	<combobox.root class="combobox" inline placeholder="Pick a fruit">		<combobox.label class="label">Favourite fruit</combobox.label>		<div class="field">			<combobox.input class="input" />			<combobox.trigger class="show">				<lucide.chevrondown class="show-icon" aria-hidden="true" />			</combobox.trigger>		</div>		<combobox.content class="list">			<combobox.item class="option" value="apple" label="Apple">				<combobox.itemlabel>Apple</combobox.itemlabel>				<combobox.itemindicator class="tick">					<lucide.check class="tick-icon" aria-hidden="true" />				</combobox.itemindicator>			</combobox.item>			<combobox.item class="option" value="banana" label="Banana">				<combobox.itemlabel>Banana</combobox.itemlabel>				<combobox.itemindicator class="tick">					<lucide.check class="tick-icon" aria-hidden="true" />				</combobox.itemindicator>			</combobox.item>			<combobox.item class="option" value="cherry" label="Cherry">				<combobox.itemlabel>Cherry</combobox.itemlabel>				<combobox.itemindicator class="tick">					<lucide.check class="tick-icon" aria-hidden="true" />				</combobox.itemindicator>			</combobox.item>			<combobox.item class="option" value="mango" label="Mango">				<combobox.itemlabel>Mango</combobox.itemlabel>				<combobox.itemindicator class="tick">					<lucide.check class="tick-icon" aria-hidden="true" />				</combobox.itemindicator>			</combobox.item>			<combobox.item class="option" value="orange" label="Orange">				<combobox.itemlabel>Orange</combobox.itemlabel>				<combobox.itemindicator class="tick">					<lucide.check class="tick-icon" aria-hidden="true" />				</combobox.itemindicator>			</combobox.item>		</combobox.content>	</combobox.root>;}

A combobox is a text field with a list of options under it. Use it when the list is long enough that people want to type to find an option. For a short list with no typing, use select.

Focus stays in the text field the whole time. The arrow keys move a highlight through the options, but the caret never leaves the field. Even a click on an option puts focus back in the field.

When a person picks an option, the field shows that option's label. If you leave label out, the field shows the value.

Anatomy

combobox anatomy
Anatomy perspectiveFlat
Layers
Your workspaceDesign studioDesign studio✓EngineeringCustomer care
combobox.root

Holds the selection and connects the label, input or trigger, and options.

combobox.input is the only Tab stop. combobox.trigger opens and closes the list with a click, but Tab skips it. Screen readers hear it as "Show options".

Filtering is yours

The family does not filter the list. It keeps the typed text, and you render the options you want. onInput on the root gets the text on every keystroke. A component inside the root can also read it as combobox.state().input.

Keyboard

Key What it does
Down arrow Open the list on the first option, or move the highlight down.
Up arrow Open the list on the last option, or move the highlight up.
Home or End While the list shows, highlight the first or last option. Otherwise, move the caret.
Page Down or Page Up While the list shows, move the highlight ten options.
Enter While the list shows, pick the highlighted option. Otherwise, submit the form.
Escape Close the list. The choice stays as it was.
Tab Close the list and move on.
Backspace With multiple and removeOnBackspace, in an empty field, remove the last choice.

The highlight stops at the ends. Set loop to make it wrap. It skips disabled options.

Choosing and unchoosing

A click on an option picks it and closes the list. A click on the option that is already picked unpicks it and leaves the list open. Without multiple, an empty field also clears the choice.

With multiple, the root's value is a list, and the list stays open after each pick. With inline, the list is always on the page. Nothing opens or closes it.

Help and errors

combobox.description is a hint and combobox.error is an error message. The input lists both in aria-describedby, the error first. The error has role="alert", so a screen reader reads it when it appears.

Forms

combobox.field renders a hidden native <select> for the form. It reads name, required and disabled from the root, and submits the chosen value.

Styling

The family ships no CSS. It writes these attributes:

Attribute On When
ui-open, ui-closed root, input, trigger, content The list is open or closed.
ui-highlighted item The keyboard or the pointer has this option highlighted.
ui-selected item This option is picked.
ui-disabled root, item The combobox or this option is disabled.
ui-value item Always. It holds the option's value.
ui-hidden itemindicator Its option is not picked.
ui-required root required is set.
ui-inline root inline is set.

combobox.itemindicator stays in the page while its option is not picked. Hide it with [ui-hidden] { visibility: hidden }.

Props on combobox.root

Prop Type What it does
value string | readonly string[] The picked option. With multiple, the list of picked options.
open boolean Whether the list starts open. The default is false.
multiple boolean More than one option can be picked, and value becomes a list.
inline boolean The list is part of the page and always shows.
loop boolean The highlight wraps at the ends instead of stopping.
removeOnBackspace boolean Backspace in an empty field removes the last choice. Needs multiple.
disabled boolean Nobody can type or pick.
required boolean The form will not submit without a choice.
invalid boolean Sets aria-invalid="true" on the input.
name string The name combobox.field submits under.
placeholder string The field's placeholder. It replaces any placeholder on the input.
onChange (value: string | readonly string[]) => void Called with the new choice.
onInput (value: string) => void Called with the field's text on every keystroke.
onOpenChange (open: boolean) => void Called when the list opens or closes.

Every other prop goes on the root <div>, which has role="group". combobox.item takes value, which it needs, plus label and disabled.