Skip to content

React Combobox With Search

A React combobox with search in the style of Select2: type to filter, pick one or many as animated chips, group or create options, or search a server as you type.

npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/combobox.json

Searchable, single

Type to filter. Arrow keys move, Enter picks, Escape closes.

Shipping

Where should we send your order?

Files to copy

7 folders · 12 files · 4 packages
From theme/src/
  • components/combobox/
  • components/spinner/
  • components/status-icons/
  • hooks/{use-direction.ts, use-latest.ts, use-media-query.ts, use-preferences.ts, use-virtual-window.ts}
  • motion/tokens.ts
  • lib/{cn.ts, field-size.ts, glide-highlight.tsx, group-segments.ts, popup-a11y.ts, popup-motion.ts}
  • styles/
shadcn CLI
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/combobox.jsonRegistry item: combobox. The styles need the Tailwind v4 glass UI setup.
Packages
pnpm add @base-ui/react clsx motion tailwind-merge

Multiple with chips, groups and a limit

Chips pop in and out. Backspace removes the last one; Left Arrow moves into the chips.

Your profile

Skills show on your public profile.

Pick up to 5.3/5

Creatable tags

Type something new and choose “Create …” to add it.

New issue

Label it so the right people see it.

Results come from a (pretend) server as you type, with a loading state. Try “ra” or “sh”.

Invite to workspace

They get an email with a link to join.

Thousands of options

Windowed above 200 options (virtualized defaults to auto): filtering runs over all 5,000, only the visible rows are in the DOM, the arrow keys and aria-activedescendant follow the active option, and group headings stay in order. Type 'Item 4999' or arrow down.

Props

PropTypeDefaultDescription
optionsComboboxOption[][]All options. With loadOptions, these are shown before the user types.
labelReactNodeNoneVisible label above the field. Without one, pass aria-label or aria-labelledby.
descriptionReactNodeNoneHelper text under the field; replaced by error when there is one.
errorReactNodeNoneShows an error message under the field. Marks the field invalid and is announced.
placeholderstring"Search…"Sets the placeholder of the text input.
onCreate((label: string) => ComboboxOption | Promise<ComboboxOption>)NoneLet users add an option that isn't in the list. Return the new option (or a promise of it).
loadOptions((query: string) => Promise<ComboboxOption[]>)NoneFetch options from a server as the user types (debounced). Errors are caught and shown in the popup.
debounceMsnumber250Sets the debounce for loadOptions, in ms.
onError((error: unknown) => void)NoneCalled when loadOptions or onCreate throws, for logging. The UI already shows the error.
onOpenChange((open: boolean) => void)NoneCalled with the new state when the popup opens or closes.
clearOnEscapebooleanon for single, off for multipleEscape on a closed popup clears the selection (ARIA combobox pattern). In a multiple Combobox it is off unless you set it, so one key press can't wipe every chip.
onFocusFocusEventHandler<HTMLInputElement>NoneRuns when the text input gains focus.
onBlurFocusEventHandler<HTMLInputElement>NoneBlur handler of the text input.
idstringgeneratedId of the text input; a generated one is used when omitted.
namestringNoneSubmits the selected value(s) with a form.
requiredbooleanNoneMark the field as required.
disabledbooleanNoneDisable the whole field.
readOnlybooleanNoneShow the value but do not let it change.
autoFocusbooleanNoneFocus the input on mount.
aria-labelstringNoneAccessible name when there is no visible label.
aria-labelledbystringNoneId of an element that names the field.
aria-describedbystringNoneId of extra descriptive text (the helper text is linked automatically).
aria-invalidboolean | "true" | "false"NoneForce the invalid state (also set by error).
sizeFieldSize"md"Height, consistent across every form control: "sm" 32px, "md" 40px, "lg" 48px (sm and md are 44px on touch screens), the same scale as Button.
classNamestringNoneClass for the outer wrapper (label + field + helper text), same as Input and Select.
inputClassNamestringNoneClass for the text <input> inside the field.
virtualizedboolean | "auto""auto"Windows the option list so only the options near the viewport are in the DOM: true always, false never, "auto" only above 200 options (VIRTUALIZE_THRESHOLD). Keyboard navigation, aria-activedescendant, filtering and aria-setsize / aria-posinset work across every option, and the scroll height does not change. Windowed rows are a fixed height (one line; a description is cut to fit); options are listed group by group and group headings are visual only.
emptyStateReactNode"No results found."What shows when nothing matches (a string or any node).
labelsPartial<ComboboxLabels>defaultComboboxLabelsEvery other string, for translation: labels={{ clear: "Effacer" }}. A partial object is merged over defaultComboboxLabels. Every other string, for translation: labels={{ otherGroup: "…" }}; omitted keys keep the English of defaultComboboxLabels. All 15 keys of ComboboxLabels are listed in the key table under the props table.
multiple (= false)falsefalseLets the person pick only one option.
multiple (= true) (required)trueNoneSelect2-style tags: pick many, shown as removable chips.
value (multiple = false)string | nullNoneThe selected option's value (controlled). null is no selection.
value (multiple = true)string[]NoneSets the selected values when controlled.
defaultValue (multiple = false)string | nullNoneThe selected option's value on mount (uncontrolled).
defaultValue (multiple = true)string[]NoneThe selected values on mount (uncontrolled).
onValueChange (multiple = false)(value: string | null) => voidNoneCalled with the new value, or null when cleared.
onValueChange (multiple = true)(value: string[]) => voidNoneCalled with the new list of values.
maxSelected (multiple = true)numberNoneStop adding chips after this many.
ComboboxLabels keys and English defaults (15)
Pass any key in labels; the rest keep the defaults of defaultComboboxLabels.
KeyEnglish default
otherGroupOther
placeholderMoreAdd more…
startTypingStart typing to search.
searchingSearching…
errorCouldn’t load results.
retryTry again
create(q) => `Create “${q}”`
createError(q) => `Couldn’t create “${q}”. Try again.`
clearClear selection
triggerShow options
chipsSelected
remove(l) => `Remove ${l}`
chipHintPress Backspace or Delete to remove
selectedHint(n) => `${n} selected. From the start of the input, press Left Arrow to reach the selected items.`
results(n) => (n === 1 ? "1 result" : `${n} results`)

Keyboard

KeysAction
TypeFilter the options.
Arrow Down/Arrow UpMove through the options; Arrow Down opens the list.
EnterPick the highlighted option (or create one, with onCreate).
EscapeClose the list; on a closed list it clears a single selection.
BackspaceMultiple: remove the last chip when the input is empty.
Arrow Left/Arrow RightMultiple: move between the chips from the start of the input.

Accessibility

  • The ARIA combobox pattern: an input with aria-expanded and aria-controls plus a listbox of options.
  • Result counts, loading, errors and the "create" option are announced politely; focus never leaves the input.
  • error marks the field invalid and is linked to it; chips have remove buttons with names.
  • Without a visible label, pass aria-label or aria-labelledby. Every string is translatable through the label props.

All exports on this page

  • Combobox — Searchable select (Select2-style): single or multiple selection with chips, groups, icons, a "create" option and async search.
  • defaultComboboxLabels — The English ComboboxLabels used when labels is omitted; a partial labels prop is merged over it.

When to use Combobox

  • Use Combobox as a Select2-style searchable select for a country or timezone picker, where the list has dozens of entries and people would rather type a few letters than scroll a long menu. Use it as an autocomplete for React and Tailwind projects when a plain select is too long to scan and people need to type to narrow the options.
  • Use multiple with chips for choosing tags or assignees, with maxSelected to cap the count and Backspace to remove the last chip from the keyboard.
  • Use loadOptions for a user search backed by an API; requests are debounced by debounceMs, and loading, empty and failed states with a Try again option are shown in the popup.
  • Skip it when there are only a handful of fixed options. Use Select for a short list, RadioGroup for two or three visible choices, or Command for an app-wide action search.
  • Pair it with Field or react-hook-form through name, ref and onBlur, Badge or Avatar as option icons, and Button for the submit step of the form around it.

Looking for Select2 in React?

Select2 is a jQuery plugin for searchable selects, tags and remote data. SheenUI's Combobox gives the same features in React without jQuery: type to filter, multiple selection as removable chips, grouped options, created options through onCreate and async search through loadOptions, built on Base UI's Combobox so the ARIA pattern is correct.

Frequently asked questions

67 components pages in all: browse them on All components.

By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .