Question presented to candidate: "Our profile form needs a 'Skills' picker. Users open a dropdown, filter by typing, and pick as many skills as they like; picked skills appear as chips in the field and each chip can be removed. It must work with the keyboard and close when you click away."
Requirements:
- A field showing the selected values as chips (each with a remove button) followed by a search input; the dropdown lists options with a checkmark for selected ones.
- Typing filters options; Up / Down move the highlight; Enter toggles the highlighted option and the dropdown stays open for more picks; Escape closes.
- Backspace in an empty search removes the last chip; removing a chip returns focus to the input.
- "Select all shown" adds every currently visible option (disabled when they are all selected already); "Clear all" empties the selection.
- The emitted value is an array of option ids in the options order, whatever order they were clicked in; close on an outside press or when focus leaves; announce changes politely.
What a strong answer should cover:
- Controlled value (array of ids) with a
Setderived for O(1) membership checks while rendering. - Normalising the value to the options order so the output is stable.
- A
listboxwitharia-multiselectable="true"wherearia-selectedmeans chosen (unlike a single-select popup, where it marks the highlighted option), andaria-activedescendantfor the highlight. - Focus management for chip removal and Backspace, and
mousedownpreventDefaulton options. - Outside-press and focus-leave closing, and a live region for "React selected. 3 selected."
Clarifying questions expected:
- "Is there a maximum number of selections?"
- "Should the selection order matter, or is the options order fine?"
- "Do 'Select all' and 'Clear' apply to the filtered options or to everything?"
Code / implementation expected: Yes. A reusable, controlled multi-select component with chips, filtering and keyboard support.