Skip to content

Commit ba8fd51

Browse files
vaadin-botsissbrueckerclaude
authored
fix: deselect items by ID in MultiSelectComboBox (#10217) (#10218)
Co-authored-by: Sascha Ißbrücker <sissbruecker@vaadin.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 4b649b8 commit ba8fd51

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

‎vaadin-combo-box-flow-parent/vaadin-combo-box-flow/src/main/java/com/vaadin/flow/component/combobox/MultiSelectComboBoxSelectionModel.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ private boolean doUpdateSelection(Map<Object, TItem> addedItems,
130130
return false;
131131
}
132132
// Remove items
133-
new LinkedHashMap<>(removedItems).forEach(selection::remove);
133+
removedItems.keySet().forEach(selection::remove);
134134
// Add items
135135
selection.putAll(addedItems);
136136

‎vaadin-combo-box-flow-parent/vaadin-combo-box-flow/src/test/java/com/vaadin/flow/component/combobox/MultiSelectComboBoxSelectionWithIdProviderTest.java‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,20 @@ void select_selectDuplicate_noChanges() {
6868
.selectionChange(Mockito.any());
6969
}
7070

71+
@Test
72+
void select_deselectDuplicate_nothingSelected() {
73+
// Select "Amelia"
74+
comboBox.select(new Person(2, "Amelia"));
75+
// Deselect "amelia", but with same ID
76+
comboBox.deselect(new Person(2, "amelia"));
77+
78+
// Should be deselected
79+
Assertions.assertEquals(0, comboBox.getSelectedItems().size());
80+
// Change listener triggered for select and deselect
81+
Mockito.verify(selectionListenerSpy, Mockito.times(2))
82+
.selectionChange(Mockito.any());
83+
}
84+
7185
@Test
7286
void selectMultiple_ignoresDuplicates() {
7387
// Select 3 duplicates of the same person

0 commit comments

Comments
 (0)