83Build a multi-select dropdown with search and tags
mediumAbout 40 minutesCodingreactaccessibilitycomboboxkeyboard
Problem
Build <MultiSelect options={options} value={selected} onChange={setSelected} label="Skills" />, a controlled multi-select. options is an array of { value, label }; value is an array of selected values.
- Selected options appear as tags; each tag has a remove button labelled
Remove {label}. - An
<input role="combobox" aria-label={label}>filters the options as you type (case-insensitive, on the label) and opens a<ul role="listbox" aria-multiselectable="true">. - Each option is
<li role="option" aria-selected>; clicking it toggles it. ArrowDownandArrowUpmove an active option (exposed witharia-activedescendant),Entertoggles it,Escapecloses the list.Backspacein an empty input removes the last selected value.- When the filter matches nothing, show
<li>No matches</li>(not an option).
Try it yourself
Write your solution, run it, then submit to check it against the tests.
App.jsxReact + DOM
Step-by-step
The selection lives in the parent (value and onChange). The component only owns UI state: query, open and activeIndex.
Unlock the full solution
What's inside
- Step-by-step
- Approach
- Solution
- Complexity
- Edge cases
- Follow-up questions
- Tests
Includes 2 code listings, 5 edge cases, 4 follow-up questions.
One-time payment by UPI, card or net banking. Launch price.