Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Combobox examples · Custom Actions

Async/Dynamic Search Combobox for React

A combobox that fetches its options as you type, with a spinner while it searches.

Framework
UI library

A search-as-you-type combobox. The list starts with Start typing to search, shows a spinner and Searching... while a request runs, then lists what came back. Here a half-second timer stands in for the request and returns three results built from your text. Use it for users, products or anything too large to load up front.

Preview

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

FAQ

How does a search run?

The typed text goes into state, and an effect starts a 500 ms timer whenever it changes. When the timer fires, the results are stored and the spinner goes away. Typing again clears the old timer first, so only the last text is searched.

Why doesn't the combobox filter the results itself?

The server already did. The list shows the results as they come back. filter is null, so the combobox shows items as they are.

Which states can the popup show?

Start typing to search with an empty box, a Spinner and Searching... while waiting, the results when they arrive, and No results found. when a search returns nothing.

How do I call a real API?

Fetch in place of the timer, and ignore responses for a search that's no longer current, for example with an AbortController in the effect's cleanup.

What does the button show?

The picked result, or Search dynamically... before a pick.

Is the input debounced?

Yes, by the timer: a request starts only after typing pauses for 500 ms. Keep a short delay like this so a fast typist doesn't send a request per key.