Frontend School

Dynamic Multi-Select Filter Component

Machine Coding
hard

Dynamic Multi-Select Filter Component

Hard
React
TypeScript
UI Components
Dropdown
Multi-Select
Accessibility
State Management

Overview

As part of enhancing the product discovery experience on Amazon, we're building a new generation of dynamic filtering components. This problem focuses on creating a robust and accessible multi-select dropdown that allows users to quickly filter large sets of product attributes. A well-designed, performant, and intuitive filtering mechanism is crucial for improving customer satisfaction and conversion rates on complex product pages.

What you need to do / Task

Your primary task is to implement a reusable MultiSelectDropdown React component that fulfills the following requirements:

  1. Core Selection Logic: Implement the functionality to select and deselect multiple options from a predefined list.
  2. Dropdown Toggle: The dropdown panel should open and close when its trigger element is clicked.
  3. Option Display: Display the available options within the dropdown, each with a checkbox to indicate its selection status.
  4. Search/Filter: Include an input field within the dropdown panel that allows users to filter the displayed options dynamically based on a search term. The search should be case-insensitive.
  5. "Select All" / "Clear All": Provide controls within the dropdown to select all currently filtered options or clear all selected options.
  6. Display Selected Items: Outside the dropdown trigger, display the currently selected items as "tags" or "pills". Each tag should be dismissible (clickable to deselect the item).
  7. Empty State: Handle cases where no options are available or no search results are found.

UI/UX expectations

  • Layout: The component should consist of a primary trigger (e.g., a button or input-like element) that, when clicked, reveals a dropdown panel. The panel should contain a search input, a list of selectable options (with checkboxes), and "Select All" / "Clear All" buttons. Selected items should appear as dismissible tags below the trigger.
  • Interactions:
    • Clicking the trigger toggles the dropdown's visibility.
    • Clicking an option's checkbox (or the option text itself) toggles its selection status.
    • Typing in the search input immediately filters the options list.
    • Clicking "Select All" selects all currently visible/filtered options.
    • Clicking "Clear All" deselects all currently selected options (not just filtered ones).
    • Clicking a selected item's dismiss button (or the tag itself) deselects that item.
    • Clicking outside the dropdown panel should close it.
  • Accessibility:
    • The component must be navigable via keyboard (e.g., Tab to focus trigger, Arrow keys to navigate options within the open dropdown, Enter/Space to select/deselect).
    • Appropriate ARIA attributes (e.g., aria-haspopup, aria-expanded, aria-controls, aria-selected, role="listbox", role="option") should be used to convey the component's state and structure to assistive technologies.

Acceptance criteria

  • Dropdown opens/closes correctly on trigger click and outside click.
  • Individual options can be selected and deselected.
  • Search input filters options list in real-time.
  • "Select All" button selects all options matching the current search filter.
  • "Clear All" button deselects all currently selected options.
  • Selected options are displayed as dismissible tags below the component.
  • Keyboard navigation (Tab, Arrow keys, Enter, Space, Escape) is fully functional for all interactive elements.
  • All interactive elements have appropriate ARIA attributes for accessibility.
  • The component gracefully handles empty option lists and no search results.

Constraints

Constraints & assumptions

  • Technology Stack: You must use React with TypeScript.
  • Data Structure: Options will be an array of objects, each with at least an id (unique string) and label (string).
    interface Option {
      id: string;
      label: string;
    }
    
  • Data Size: The number of options will typically range from 10 to 100.
  • Styling: Basic functional styling is expected to make the component usable and clear. Pixel-perfect design is not required, but the component should be visually distinguishable and functional. You may use plain CSS.
  • No External UI Libraries: Do not use any third-party UI component libraries (e.g., Material UI, Ant Design, Chakra UI). You are expected to build this component from scratch using native HTML elements and React.

Out of scope

  • Asynchronous Data Loading: Assume all options are available upfront. No need to implement API calls or loading states.
  • Complex Animations: Basic transitions are fine, but elaborate animations are not required.
  • Advanced Theming: Focus on functionality and basic layout, not a comprehensive theming system.
  • Performance Optimization for Thousands of Items: While efficiency is good, don't over-optimize for edge cases beyond 100 items.

What interviewers evaluate

  • Component Design & State Management: Clarity, correctness, and efficiency of React component structure, props, and internal state.
  • Functional Correctness & Edge Cases: Accuracy of all specified functionalities (selection, search, select/clear all, dismiss) and robust handling of edge cases (empty lists, no search results).
  • Accessibility Implementation: Correct and comprehensive application of keyboard navigation and ARIA attributes.
  • Code Quality & Maintainability: Readability, organization, type safety, and overall maintainability of the codebase.

Loading editor...