Problem
Build a typeahead/autocomplete input that fetches suggestions as the user types.
Requirements
- Debounce input before fetching; show a suggestions dropdown.
- Handle loading and empty states; close on outside click / Escape.
- Keyboard navigation: Up/Down to move, Enter to select.
- (Bonus) Cache results per query, cancel stale in-flight requests, highlight the matched substring.
Hints / Approach
- Debounce the query (e.g. 300ms) to limit requests.
- Guard against race conditions: track the latest request (AbortController or a request id) so a slow earlier response doesn't overwrite a newer one.
- Track
highlightedIndexfor keyboard nav; reuse an LRU cache (see "TypeAhead cache with LRU eviction").