Overview
Modern web applications often require sophisticated filtering and selection mechanisms. A multi-select dropdown is a fundamental UI component that allows users to pick multiple items from a predefined list, commonly used in dashboards, form inputs, and data filtering interfaces. This problem challenges you to build a robust and user-friendly multi-select dropdown component, focusing on core functionality, reusability, and good user experience.
What you need to do / Task
You are tasked with creating a MultiSelectDropdown React component that fulfills the following requirements:
- Component Design: Create a reusable
MultiSelectDropdown component that accepts a list of Option objects and manages its internal state for selected items.
- Dropdown Toggle: Implement a button that toggles the visibility of the dropdown list.
- Multi-Selection: Allow users to select and deselect multiple options from the list. Each option should have a checkbox or similar visual indicator.
- Display Selected Items: Display the currently selected items as interactive "chips" or "tags" outside the dropdown list itself. Each chip should include the item's label and a button to remove it from the selection.
- Clear All: Provide a "Clear All" action within the dropdown list to deselect all chosen options.
- Outside Click: The dropdown list should close when a user clicks anywhere outside of the component.
UI/UX expectations
- Dropdown Toggle: A clear button or input field that indicates the current selection count or placeholder text when nothing is selected. It should visually respond to user interaction.
- Option List: When open, the dropdown should display a scrollable list of available options. Each option should clearly show its selected/unselected state (e.g., via a checkbox).
- Selected Chips: Chips for selected items should be visually distinct, clearly labeled, and include an 'x' button for deselection. They should appear below or adjacent to the dropdown toggle.
- Responsiveness: The component should be reasonably responsive, adapting to typical desktop screen sizes.
- Accessibility (Basic): Ensure basic ARIA attributes are used for the dropdown toggle (
aria-haspopup, aria-expanded) and options (role="option", aria-selected) to convey state to assistive technologies.
Acceptance criteria
- The
MultiSelectDropdown component renders correctly with provided options.
- Clicking the toggle button opens and closes the dropdown list.
- Clicking an option in the list toggles its selection state (adds/removes it from the selected list).
- Selected options are visually represented as chips outside the dropdown.
- Clicking the 'x' button on a chip removes that item from the selection.
- Clicking the "Clear All" button deselects all options and removes all chips.
- Clicking outside the dropdown component closes the dropdown list.
- Basic ARIA attributes are applied to enhance accessibility.