Frontend School

Interactive Feature Combobox

Machine Coding
medium

Interactive Feature Combobox

Medium
React
UI
Accessibility
Combobox
Keyboard Navigation

Overview

Tesla's vehicle configuration platform relies on highly interactive and user-friendly components to streamline the selection process for various features, from wheel types to interior trims. A well-implemented Combobox component is crucial for allowing users to quickly find and select options from a potentially large dataset, enhancing overall user experience and reducing configuration time.

What you need to do / Task

Your task is to build a Combobox React component that allows users to search, filter, and select an item from a predefined list of vehicle features. The component should be highly interactive and accessible.

  1. Render the Combobox: Display an input field and, when active, a dropdown list of suggestions.
  2. Filter Options: As the user types into the input field, dynamically filter the VEHICLE_FEATURES list (provided in App.tsx) based on the input value. Filtering should be case-insensitive and match anywhere within the feature name.
  3. Display Suggestions: Show the filtered options in a dropdown list below the input. If no matches are found, display a message (e.g., "No matching features").
  4. Selection: Allow users to select an option by clicking on it in the dropdown or by navigating with keyboard arrows (Up/Down) and pressing Enter.
  5. Update Input: Upon selection, the input field should display the selected feature's name, and the dropdown should close.
  6. Debounce Input: Implement a debounce mechanism for the input field's filtering logic to prevent excessive re-renders during rapid typing.

UI/UX expectations

  • Layout: The input field should be clearly labeled. The dropdown list should appear directly below the input when suggestions are available and the input is focused.
  • Interactions:
    • Typing in the input should update the suggestions list in real-time (with debouncing).
    • Hovering over a suggestion should highlight it.
    • Keyboard Up and Down arrows should navigate through the suggestions, highlighting the currently focused item. The input field should retain focus during this navigation.
    • Pressing Enter on a highlighted suggestion should select it.
    • Clicking a suggestion should select it.
    • Clicking outside the Combobox should close the dropdown if it's open.
  • Accessibility: The component should be accessible to users relying on assistive technologies. Implement appropriate ARIA attributes (e.g., aria-haspopup, aria-expanded, aria-autocomplete, role="combobox", role="option", aria-activedescendant).

Acceptance criteria

  • The input field correctly filters the VEHICLE_FEATURES list based on user input.
  • The dropdown list displays only the filtered, matching options.
  • Keyboard Up and Down arrows navigate focus within the dropdown suggestions.
  • The Enter key selects the currently highlighted option from the dropdown.
  • Clicking an option in the dropdown selects it and updates the input field.
  • The input field displays the selected feature's name after selection.
  • The dropdown list hides automatically when an option is selected or when the component loses focus (e.g., clicking outside).
  • Input filtering is debounced by 300ms.
  • Appropriate ARIA attributes are used to enhance accessibility.

Constraints

Constraints & assumptions

  • You must use React for building the UI component.
  • The list of vehicle features is provided as a static array (VEHICLE_FEATURES) within App.tsx.
  • Filtering should be case-insensitive and match substrings.
  • The debounce time for input filtering should be 300ms.
  • The input field should retain focus when navigating the dropdown list using keyboard arrows.
  • Assume modern browser environments.

Out of scope

  • Backend integration or API calls for fetching data.
  • Extensive, pixel-perfect styling. Focus on functionality and basic readability.
  • Complex error handling for invalid input types (assume string input).
  • Multi-select functionality for features.

What interviewers evaluate

  • Functional Correctness: Does the Combobox perform all required filtering, selection, and interaction behaviors accurately?
  • Code Quality & Structure: Is the React component well-structured, modular, and easy to understand? Are hooks used appropriately?
  • State Management: Is component state managed effectively to handle user input, dropdown visibility, and selected values?
  • Accessibility Implementation: Are ARIA attributes correctly applied, and is keyboard navigation robust?
  • Performance Optimization: Is the debouncing mechanism correctly implemented for input filtering?

Loading editor...