Steps to replicate the issue (include links if applicable):
- Create a OO.ui.SelectWidget with multiple options.
- Select several options, including one to be removed, and some that will not be removed.
- Call removeItems([optionToRemove]).
What happens?:
All selected options are deselected including ones that were not removed.
I believe the issue is the for loop at https://doc.wikimedia.org/oojs-ui/master/js/widgets_SelectWidget.js.html#line1067
OO.ui.SelectWidget.prototype.removeItems = function ( items ) {
// Deselect items being removed
for ( let i = 0; i < items.length; i++ ) {
const item = items[ i ];
if ( item.isSelected() ) {
this.selectItem( null );
}
}The issue is that removeItems calls this.selectItem(null) for any selected item being removed. Passing null deselects all options in the widget, not just the one being removed, which contradicts the comment and causes unexpected deselection of unrelated selected options. The argument should instead be the specific item being removed.
Making the issue worse is that it's inconsistent. If none of the removed options are selected, everything works as expected, but if any one option of the removed set is selected, then everything is deselected including non-removed options.
What should have happened instead?:
Only the removed items should be deselected. Other selections should be unaffected.
Software version (on Special:Version page; skip for WMF-hosted wikis like Wikipedia):
current English Wikipedia