Toggle selected items immutably
Build a controlled multi-select list that preserves item order and never mutates incoming values.Description
Requirements
The solution exports the required SelectableItems API from the editable module.
Toggle on off works deterministically for the documented normal, boundary, and repeated-use scenarios.
Multiple selection works deterministically for the documented normal, boundary, and repeated-use scenarios.
Stable order works deterministically for the documented normal, boundary, and repeated-use scenarios.
Immutable items works deterministically for the documented normal, boundary, and repeated-use scenarios.
Controlled state works deterministically for the documented normal, boundary, and repeated-use scenarios.
Every interactive control supports its documented keyboard behavior and exposes an accessible name.
Toggle twice
Activate Alpha, then activate Alpha again
The first callback includes alpha and the second callback excludes it
Each callback receives a new array and the incoming selectedIds value is untouched.
Constraints
Keep the component controlled by selectedIdsEmit IDs in source item orderUse keyboard-operable controls with selection state
Hints
Hint 1
Derive the next membership set from the controlled value inside the click handler.
Hint 2
Map the source items to produce stable output ordering instead of appending blindly.
Hint 3
Use aria-pressed on toggle buttons so assistive technology receives the state.