Frontend School

Typeahead Restaurant Search Combobox

Machine Coding
easy

Typeahead Restaurant Search Combobox

Easy
React
TypeScript
UI
Combobox
Search

Overview

At Swiggy, enabling users to quickly find their desired restaurants is paramount to a seamless food ordering experience. A highly efficient search bar, often implemented as a typeahead or combobox component, is a critical part of this. It helps users discover restaurants even with partial input, reducing friction and improving satisfaction. This problem challenges you to build a foundational typeahead search component for restaurants.

What you need to do / Task

Your primary task is to build a functional and user-friendly Combobox React component that allows users to search for restaurants from a predefined list.

  1. Create a Combobox component: This component should accept a list of Restaurant objects as a prop.
  2. Implement search filtering: As the user types into the input field, the component should filter the provided Restaurant list. The filtering should be a case-insensitive substring match against the name property of each restaurant.
  3. Display suggestions: Matching restaurants should be displayed in a dropdown list that appears below the input field.
  4. Handle selection: When a user clicks on a suggestion in the dropdown, the input field should be updated with the selected restaurant's name, and the dropdown should close.
  5. No results message: If the search yields no matching restaurants, a clear "No results found." message should be displayed within the dropdown area.

UI/UX expectations

  • An input field should be prominently displayed for user typing.
  • A dropdown list of suggestions should appear directly below the input field only when there are matching results and the input is focused/active.
  • Each suggestion in the dropdown should be clickable.
  • Upon selection, the dropdown should disappear, and the input field should reflect the selected item's name.
  • Basic, clean styling to ensure readability and functional presentation (e.g., clear borders, distinct hover states for suggestions).

Acceptance criteria

  • [ ] A text input field is rendered and allows user input.
  • [ ] Typing in the input field correctly filters the provided restaurant list (case-insensitive substring match).
  • [ ] A dropdown list displays filtered suggestions when available.
  • [ ] Clicking a suggestion item updates the input field with the selected restaurant's name.
  • [ ] The dropdown list closes immediately after a selection is made.
  • [ ] The message "No results found." is displayed when no restaurants match the current input.
  • [ ] The dropdown list is hidden when the input is empty or loses focus (and no selection has been made).

Constraints

Constraints & assumptions

  • Data Size: The list of restaurants will be small, typically not exceeding 50-100 items. Client-side filtering is sufficient.
  • Filtering Logic: Simple case-insensitive substring matching against the name property of Restaurant objects.
  • Environment: You should use React with TypeScript.
  • No API Calls: All restaurant data will be provided as a prop; no external API fetches are required.
  • Styling: Use plain CSS or inline styles. No external UI libraries (e.g., Material UI, Ant Design).

Out of scope

  • Full keyboard navigation (e.g., using arrow keys to navigate suggestions, Enter to select).
  • Debouncing search input (not necessary for small client-side data).
  • Advanced accessibility features (e.g., ARIA roles beyond basic semantic HTML).
  • Loading states or error handling.
  • Complex animations or transitions.

What interviewers evaluate

  • Functional Correctness: Does the component meet all specified functional requirements and acceptance criteria?
  • React Component Design: Is the Combobox component well-structured, reusable, and does it manage its state effectively?
  • TypeScript Usage: Are types used correctly and consistently, enhancing code clarity and preventing common errors?
  • Code Quality: Is the code clean, readable, maintainable, and does it follow React best practices?
  • UI/UX Adherence: Does the component provide a user experience that aligns with the specified UI/UX expectations?

Loading editor...