Frontend School

Configurable Multi-Select Tag Input

Machine Coding
hard

Configurable Multi-Select Tag Input

Hard
React
TypeScript
Frontend
UI/UX
Machine Coding
Accessibility

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:

  1. Core Functionality: Implement a multi-select dropdown where users can select multiple items from a predefined list of options.
  2. Tag Display: Display all selected options as interactive 'tags' or 'chips' below the input field. Each tag should be individually removable.
  3. Search/Filter: The dropdown should include an input field that allows users to filter the available options dynamically as they type.
  4. 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).
  5. 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).
  6. 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.

Constraints

Constraints & assumptions

  • Data Structure: Options will be provided as an array of objects, each with a unique id (string or number) and a label (string). Example: [{ id: 'us', label: 'United States' }, { id: 'in', label: 'India' }].
  • Option Count: The component should efficiently handle up to 1000 options without significant performance degradation during filtering or rendering.
  • Styling: You are free to use pure CSS or CSS modules. No external UI frameworks (e.g., Material UI, Ant Design) are allowed.
  • Environment: React functional components with Hooks and TypeScript.
  • Browser Support: Modern browsers (Chrome, Firefox, Edge).

Out of scope

  • API integration for fetching options (mock data is sufficient).
  • Advanced features like drag-and-drop reordering of tags, grouping of options, or virtualized lists (unless performance becomes a critical issue with 1000 items).
  • Full screen reader accessibility (though basic keyboard navigation is a must).
  • Debouncing for search input (simple real-time filtering is fine).

What interviewers evaluate

  • Component Architecture: How well the component is structured, its reusability, and separation of concerns.
  • State Management: Efficient and correct use of React state and hooks to manage selection, search, and dropdown visibility, minimizing unnecessary re-renders.
  • UI/UX Fidelity: Accuracy in implementing the specified UI/UX behaviors, including tag display, search, and the Select All/Deselect All logic.
  • Accessibility & Interactivity: Implementation of robust keyboard navigation and external click handling.
  • Code Quality: Readability, maintainability, type safety (TypeScript usage), and overall code cleanliness.

Loading editor...