Skip to content
Shubham JangleResources
React

Explore topics

Auto-complete search box

Watch the walkthrough
Open on Instagram

Exercise: Build an autocomplete search input

Create a controlled text input that requests matching suggestions and shows a dropdown. Selecting a suggestion should update the input and notify the parent. Use mock results such as cities or products with stable IDs.

Requirements

  • Define a minimum query length and clear suggestions when the input is empty.
  • Show loading, no matches, and request failure separately.
  • Support Arrow Up/Down, Enter to select, and Escape to close; keep the highlighted option visible.
  • Use combobox/listbox semantics and allow pointer selection without losing the click on input blur.

Acceptance checks and discussion

Type a query, navigate with the keyboard, and choose a result. Resolve an older request after a newer one: the older result must not overwrite the current suggestions. The optimization lesson adds debounce and caching.

The brief above is an original practice specification. The linked sandbox is supporting solution material and may implement a simpler subset of these requirements.

Supporting material