Build an Accessible Flight Destination Combobox
At Ixigo, providing a seamless and efficient booking experience is paramount. A critical part of this is the destination selection process, where users need to quickly find and select their desired city or airport. This problem challenges you to build a robust and accessible Combobox component, similar to what we use for flight destination inputs, enhancing user experience by offering dynamic suggestions and easy navigation.
Your primary task is to develop a Combobox React component that allows users to type into an input field and receive real-time suggestions from a predefined list of options.
Specifically, you need to:
Combobox component: This component should accept options: string[] and onSelect: (value: string) => void as props, along with an optional placeholder: string.options prop and display only those that match the current input (case-insensitive substring match).onSelect callback.ArrowUp and ArrowDown keys. The currently highlighted suggestion should be visually distinct.Enter when a suggestion is highlighted should select it.Escape should close the dropdown without selecting an option.Combobox should consist of an input field and a dynamically rendered list of suggestions.onSelect callback with the selected value.ArrowUp and ArrowDown keys correctly navigate through the suggestions, with visual highlighting.Enter on a highlighted suggestion selects it, updates the input, and calls onSelect.Escape closes the dropdown and clears any active highlighting without selecting.role="combobox", aria-autocomplete, aria-expanded, aria-activedescendant, aria-controls).Constraints
string[]). Assume the data is pre-loaded and available directly as a prop.Combobox component, including prop handling and internal state management.Loading editor...