Frontend School

Groww Financial Instrument Autocomplete Search

Machine Coding
hard

Groww Financial Instrument Autocomplete Search

Hard
React
TypeScript
Frontend
Autocomplete
Search
Debounce
UX

Overview

Groww is a leading investment platform, and a seamless user experience is paramount. A crucial part of this experience is the ability for users to quickly find the financial instruments (stocks, mutual funds, etc.) they are looking for. This problem challenges you to build a performant and user-friendly autocomplete search component, mimicking the real-world functionality critical for efficient navigation and discovery on platforms like Groww.

What you need to do / Task

Your goal is to implement a client-side autocomplete search component for financial instruments based on provided mock data. You must satisfy the following deliverables:

  1. Search Input: Render a text input field where users can type their search query.
  2. Dynamic Filtering: As the user types, filter the MOCK_DATA to find matching financial instruments. The search should be case-insensitive and match against both the name and symbol fields of each instrument.
  3. Debouncing: Implement debouncing for the search input to prevent excessive filtering operations and improve performance. The debounce time should be 300ms.
  4. Dropdown Display: Display matching results in a dropdown list below the input field. The dropdown should appear when there are search results and disappear when the input is empty, on blur, or when no results are found.
  5. Result Highlighting: Within the dropdown, highlight the specific part of the name or symbol that matches the user's search query.
  6. Keyboard Navigation: Enable keyboard navigation within the dropdown list:
    • ArrowUp/ArrowDown: Navigate through the search results.
    • Enter: Select the currently active (highlighted) result.
    • Escape: Close the dropdown.
  7. Result Selection: When an item is selected (either by click or Enter key), display the selected instrument's details prominently below the autocomplete component. The search input should be cleared, and the dropdown should close.
  8. No Results Feedback: Display a clear message in the dropdown if no results are found for the current search term.

UI/UX expectations

  • The search input should be clearly visible and styled.
  • The dropdown should appear directly below the input, with a distinct background.
  • Individual search results in the dropdown should be clearly separated and show both name and symbol.
  • The active/hovered search result should have a distinct background style.
  • Matched text within results should be highlighted (e.g., with a different background color or bold font).
  • The selected instrument's details should be displayed in a clean, readable format below the search component.

Acceptance criteria

  • The search input field renders correctly.
  • Typing in the input triggers debounced search operations.
  • Search results accurately match name or symbol (case-insensitive substring match).
  • Only up to 10 results are displayed in the dropdown at any time.
  • The matched portion of the text in results is visually highlighted.
  • Keyboard ArrowUp and ArrowDown keys correctly navigate through dropdown items.
  • Pressing Enter on an active dropdown item selects it, clears the input, and displays the selected item's details.
  • Clicking a dropdown item selects it, clears the input, and displays the selected item's details.
  • The dropdown closes on Escape key press or when clicking outside the component (without selecting an item).
  • A 'No results found' message is displayed when applicable.
  • The selected instrument's details are displayed correctly after selection.

Constraints

Constraints & assumptions

  • Environment: React with TypeScript.
  • Data: All financial instrument data (MOCK_DATA) is provided upfront in the client-side code. No external API calls are required for searching.
  • Result Limit: Display a maximum of 10 search results in the dropdown at any given time.
  • Debounce Time: Use a debounce time of 300 milliseconds for search queries.
  • Focus: Prioritize functional correctness, performance considerations (debouncing), and a clean, maintainable React component structure.

Out of scope

  • Fetching data from a backend API.
  • Implementing complex search ranking algorithms (e.g., fuzzy matching, relevance scoring).
  • Persistent storage for recent searches or user preferences.
  • Full accessibility compliance beyond basic keyboard navigation (aria-* attributes are a plus but not strictly required for the time budget).

What interviewers evaluate

  • Correctness and Completeness: How accurately and thoroughly the core autocomplete features (filtering, debouncing, highlighting, selection) are implemented.
  • Performance Considerations: Effective use of debouncing and efficient client-side filtering logic.
  • Code Quality & Design: Clean, modular, and idiomatic React component design, appropriate use of hooks, and maintainable state management.
  • User Experience (UX): Robust keyboard navigation, clear visual feedback for results, and graceful handling of edge cases like 'no results'.

Loading editor...