Autocomplete Search Bar (Standalone Component)

intermediate
By FrontendAtlas Editorial · Updated Nov 12, 2026
intermediate level
Reactive forms input binding (FormControl + ReactiveFormsModule)RxJS streams for UI behavior (valueChanges, debounce, switchMap)Bridging the results stream to the template with toSignalDropdown state in signals + click-outside handlingKeyboard navigation + a11y roles/aria
Build an autocomplete search bar in Angular. As the user types, show a dropdown of suggestions filtered from a dataset. Add debounced searching, mouse selection, and keyboard navigation (↑/↓/Enter/Escape).

Requirements

  • Use a standalone Angular component as the root component.
  • Use ReactiveFormsModule and a FormControl for the input binding.
  • Show a dropdown of suggestions filtered by the current query (case-insensitive, substring match).
  • Debounce input changes (e.g. 250–400ms) before searching.
  • Support mouse selection (mousedown on a suggestion sets the input value and closes dropdown).
  • Support keyboard navigation: ArrowDown/ArrowUp moves active option, Enter selects, Escape closes.
  • Close the dropdown when clicking outside the component.
  • Basic accessibility: use role="combobox", role="listbox", role="option", plus aria-expanded and aria-activedescendant.

What the checks look for

The checks find elements by control labelled "Search", option, listbox, body, combobox. Keep these in your markup.

Expected behavior

  • Typing updates suggestions after the debounce delay.
  • If query is empty/whitespace, dropdown is closed and no suggestions are shown.
  • ArrowDown from no selection activates the first option; ArrowUp activates the last option.
  • Enter selects the active option (if any) and closes the dropdown.
  • Escape closes the dropdown without changing the input.
  • Clicking outside closes the dropdown.

Implementation notes

  • Create a fake async search function search(q) that filters a local dataset and returns of(filtered).pipe(delay(...)).
  • Build the results stream from queryControl.valueChanges with debounceTime + distinctUntilChanged + switchMap into search().
  • Bridge the stream to the template with toSignal and read it as results(); like the async pipe, it needs no imperative subscription.
  • Keep isOpen and activeIndex in signals. The stream's tap sets them in a debounce timer callback, which no template event covers, so an OnPush view only notices through a signal write.
  • Keep the solution in a single component (no need for services).

Solution idea

Bind the input to queryControl, a FormControl, with [formControl], and build the search from its valueChanges: typing and select() both set the control's value, so one stream sees every query. The stream trims the text, waits with debounceTime(300), drops repeats with distinctUntilChanged(), and switchMaps into a fake async search() that filters a local list of cities and answers after delay(150). toSignal turns the stream into the results signal the template reads. isOpen and activeIndex are signals for dropdown visibility and keyboard navigation, and a document:mousedown listener in the component's host metadata closes the list when the click lands outside the component.

Public interview reports

These public, self-reported interview accounts informed this practice version. The exercise is modelled on reported rounds, not copied from them, and the reports are not verified official questions or endorsements.

  • Code360: Booking.com frontend engineer interview experience, April 2023 · Code360, April 2023

    One account describes a 40-minute round with three engineers: create an autocomplete text box in vanilla JavaScript, HTML and CSS, covering edge cases and must-haves versus nice-to-haves. This starter is a practice version in Angular; the reported round was framework-free.

  • enginebogie: Booking.com frontend engineer machine-coding round, May 2023 · enginebogie, May 2023

    One account describes a 60-minute machine-coding round: a typeahead with API calls, a live dropdown, highlighted matches, debounce or throttle, caching, keyboard navigation and error states. This starter is a practice version of that round in Angular, not its reported wording.

Reported in a public Booking.com interview account. Booking.com frontend interview questions