Overview
In Inmobi's campaign management platform, advertisers frequently need to define intricate targeting rules, such as selecting multiple ad formats, geographic regions, or audience segments. A robust and intuitive multi-select component is crucial for enabling efficient configuration of these complex campaigns. This problem challenges you to build a highly configurable, performant, and accessible multi-select dropdown that displays selected items as interactive tags.
What you need to do / Task
Your primary task is to develop a reusable MultiSelect React component that fulfills the following requirements:
- Core Functionality: Implement a multi-select dropdown where users can select multiple items from a predefined list of options.
- Tag Display: Display all selected options as interactive 'tags' or 'chips' below the input field. Each tag should be individually removable.
- Search/Filter: The dropdown should include an input field that allows users to filter the available options dynamically as they type.
- Select All / Deselect All: Include a special option at the top of the dropdown list. This option should dynamically toggle between "Select All" (when not all options are selected) and "Deselect All" (when all options are selected).
- Keyboard Navigation: Ensure the component is navigable using a keyboard. Users should be able to open/close the dropdown, navigate through options, select/deselect options, and remove tags using standard keyboard interactions (e.g.,
Tab, Enter, Escape, ArrowUp/ArrowDown).
- External Click Handling: The dropdown should close when a user clicks outside of the component.
UI/UX expectations
- Input Field: A primary input field that, when clicked, toggles the dropdown visibility. It should display a placeholder when no items are selected and optionally show a summary (e.g., "3 items selected") or selected tags directly within it.
- Dropdown List: A scrollable list of available options, with a maximum height. Each option should clearly indicate its selection state (e.g., a checkbox or distinct styling).
- Search Bar: An integrated search input within the dropdown to filter options.
- Selected Tags: Below the main input, selected items should be rendered as distinct tags/chips. Each tag should have its label and a small 'x' icon to remove it.
- Select All/Deselect All: This option should be visually prominent at the top of the dropdown list.
- Empty State: Handle cases where no options match the search query (e.g., display "No options found").
Acceptance criteria
- Dropdown opens/closes on click of the primary input field.
- Dropdown closes when clicking outside the component.
- Users can select and deselect individual options from the dropdown list.
- Selected options are displayed as removable tags below the input.
- Typing in the search bar filters the options list in real-time.
- The "Select All" option correctly selects all currently filtered options.
- The "Deselect All" option correctly deselects all currently filtered options.
- The "Select All" / "Deselect All" label dynamically updates based on the selection state of all available options (not just filtered ones).
- Individual tags can be removed by clicking their 'x' icon.
- Keyboard navigation works:
Tab to focus, Enter to toggle dropdown/select option, ArrowUp/ArrowDown to navigate options, Escape to close dropdown.
- The component is responsive and visually appealing.