Skip to content
SENVENLI UI

Combo box

Type to filter a long list and pick one or several items, with load-more and app-side results.
Pick one from a long list
import { ComboBox } from "@senvenli/react/selection";

Examples

Several items

Chosen items become removable tags in the field.

Create a missing item

A create row appears when nothing matches the text exactly.

Loaded from the server

A loadItems function fetches matches as people type and pages by cursor.

Guidelines

When to use it

  • Picking from a long list (customers, products, countries) by typing.

Use something else when

  • The list is short. Select
  • People search across actions and records with ⌘K, not fill a field. Command

Accessibility

Keyboard

KeysWhat happens
Arrow downOpens the list.
EnterPicks the focused option.

Built in

  • Announces the result count and "No results".
  • Matches ignore case and accents.
  • Required fields show "Fill in this field." after a blur or a submit; your own errorMessage replaces it.

You provide

  • A visible label.

API reference

ComboBox

label
React.ReactNode

The label sits above the field.

items
readonly ComboBoxItem[]

The whole list, filtered here as the user types.

loadItems
ComboBoxLoader

Or load matches from the server (with paging when it returns a cursor).

description
React.ReactNode
errorMessage
React.ReactNode
placeholder
string
isRequired
boolean
requiredValidation
RequiredValidation

Who says an empty required ComboBox is missing: field (default) shows "Fill in this field." on blur and on a DS Form submit, which it then blocks; app only marks the field. Empty is no chosen item (multiple: no tag); with allowsCustomValue, typed text counts as a value. See {@link RequiredValidation}. The app's isInvalid (true with its errorMessage, or false) overrides the check, as on TextField. Disabled, empty and required, it still blocks a DS Form's submit and cannot take focus (as TextField).

isDisabled
boolean
isInvalid
boolean
name
string
menuTrigger
"focus" | "input"

input (default) opens on typing; focus also on focus. The chevron always opens the full list.

emptyState
React.ReactNode | ((query: string) => React.ReactNode)

The empty result: a node, or a function of the typed text for a message that quotes it. Defaults to "No results for “{query}”." in the provider locale.

onCreate
(text: string) => void

Adds a create row for the typed text when nothing matches it exactly.

createLabel
(text: string) => string

The create row's text; defaults to "Add “{query}”".

onInputChange
(text: string) => void

The typed text, for consumers that need it (custom values, analytics).

size
FieldSize
isLoading
boolean

The app is fetching items itself (with items, not loadItems): a spinner shows in the field and at the end of the list, and the change is announced. Items already shown stay selectable by keyboard and pointer. Together with loadItems, the field's own loading status is the one announced, so there is a single status region.

loadingText
string

What is announced and shown while loading; defaults to "Loading…" in the provider locale.

onSearchChange
(search: string) => void

The app searches on the server itself (with items, not loadItems;): told the text to search for, the typed text, or "" when the list opens in full (the chevron, focus with menuTrigger="focus") or the field just shows the chosen item's label. Debounce it on the app side. With it, items are the app's results and are shown as given, not filtered again here; the match in each row is still in bold. Not called on mount.

The field hides rows found for another text itself: from the moment the text changes until the app's answer arrives, the list shows its loading row, the field its spinner, and the loading is announced politely, whatever the app does while it debounces. The answer has arrived when the rows change (ids, labels, second lines), when isLoading is set and cleared again (also for a server that finds the same rows), or, if neither, once the same rows have stood for a second with no new render. Nothing is asked of the app for it; isLoading is still the way to say a fetch is running.

It is for a search that answers later. Filtering the rows the app already holds, synchronously, is the local filter's job (pass items without onSearchChange): here an answer with the very same rows and no isLoading stays hidden for that second. The field tells answers apart by when they arrive, not by the text they were asked for: an earlier request that answers after the next keystroke counts as the answer to the newer text. Abort superseded requests, or keep each answer under its own text (react-query's query key, without placeholderData).

onLoadMore
() => void

The next page of the app's own items, for an app that pages with its own query (react-query's infinite query): called when the list is scrolled near its end. Pass it only while there is another page (hasNextPage ? fetchNextPage : undefined), and set isLoading while the page loads: the list then ends in a loading row, the field shows its spinner and the loading is announced (politely). It is not called again while isLoading is set, nor twice before the app answers (a new page, isLoading, or a new search). The app's error stays the app's (errorMessage, description); after it, a scroll to the end asks again. With loadItems, which pages by itself, it is not used.

id
string

The input's id, so a label outside the component (<label htmlFor={id}>, an app's form field) names it. With neither label nor aria-label, that external label is the field's name and no label of its own renders.

aria-describedby
string

Ids of text outside the component that describes the input (an app's hint or error), added to its own.

aria-invalid
boolean | "true" | "false"

Set by a form row that owns the error text (the shared Field hands its control aria-invalid): the field shows its invalid state as with isInvalid, and without an errorMessage of its own draws no error row, so the row's message is the only one. It marks the input for assistive tech and draws it invalid only: unlike isInvalid it never becomes the input's native validity (React Aria's default outside a DS Form), so it never blocks a form's submit.

selectionMode
"single" | "multiple"
selectedKey
Key

Controlled; may start undefined and become set later (never flips control).

defaultSelectedKey
Key
onSelectionChange
(key: Key | null) => void | (keys: Key[]) => void
selectedItem
ComboBoxItem

The chosen item when it is not on the loaded page (server search), so its label still shows.

allowsCustomValue
boolean

Typed text that matches no item is kept as the field's text; the key becomes null and onInputChange reports the text.

radius
ComponentRadius

Corner radius: none, small, medium (the design), large or full. The provider's default otherwise.

aria-label
string

Names the field for assistive technology when no visible label is shown.

selectedKeys
readonly Key[]
defaultSelectedKeys
readonly Key[]
selectedItems
readonly ComboBoxItem[]

Chosen items that are not on the loaded page, so their tags show their labels.