Build an autocomplete search box
How the interviewer asks it
“Build a search box that suggests matching cities as the user types, fetched from an API. Show loading, empty and error states, let the user pick a suggestion with the mouse or the keyboard, and do not send a request on every keystroke.”
Typed drills are free and unlimited: the AI scores your answer against the outline below.
What the interviewer is looking for
- A small component tree with the query, results and highlighted index owned in one place.
- Debounced requests and a guard against responses arriving out of order.
- Every state handled: idle, loading, results, no results and error.
- Keyboard support with arrow keys, Enter and Escape, and the ARIA combobox roles.
- A sensible layout on a phone, where the list must not hide behind the keyboard.
How to structure your answer
- 01
Clarify
How many results, minimum query length, what picking a result does, and whether results can be cached.
- 02
Structure
An input, a listbox of options and a status line; state for the query, results, status and the active option.
- 03
Fetching
Debounce by about 250 ms, cancel the previous request with an AbortController or ignore any response that is not for the latest query.
- 04
Accessibility
role="combobox" with aria-expanded and aria-controls, role="listbox" and "option", aria-activedescendant for the highlighted row, and a live region for the result count.
- 05
Polish
Highlight the matched text, cache recent queries, close on blur without losing a click, and test it with the keyboard only.
Best answers from candidates
No candidate answers yet. Type yours, and if it scores 6 or more you can show it here without your name.
Answers are shared by candidates, without names, after a privacy check. Add yours
Common mistakes
- Fetching on every keystroke with no debounce.
- Letting a slow, older response overwrite the newer results.
- A list of clickable divs that a keyboard or screen reader user cannot reach.
Follow-up questions to expect
- Responses can arrive out of order, so a slow reply for "ban" lands after "bang". How do you make sure the list always matches what is in the box?
- How would you test this component?
Now answer it out loud
Max will ask you this exact question, listen to your answer, push on the weak spots with follow-ups like the ones above, and score you when you finish.
Practice with MaxFree: a 5-minute voice round and unlimited typed drills, with scored feedback. No card, and your camera is never recorded.