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.
- Render the Combobox: Display an input field and, when active, a dropdown list of suggestions.
- 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.
- 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").
- 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.
- Update Input: Upon selection, the input field should display the selected feature's name, and the dropdown should close.
- 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.