Skip to content

Commit

Permalink
Merge pull request #4121 from IgniteUI/vslavov/combo-empty-selection
Browse files Browse the repository at this point in the history
fix(selection): do not clear selection on `add_items` with empty array
  • Loading branch information
mpavlinov authored Mar 2, 2019
2 parents 24066a0 + ac557f5 commit 4755c24
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
21 changes: 21 additions & 0 deletions projects/igniteui-angular/src/lib/combo/combo.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1060,6 +1060,27 @@ describe('igxCombo', () => {
cancel: false
});
}));

it(`Should properly handle 'selectItems([]) call'`, fakeAsync(() => {
const fix = TestBed.createComponent(IgxComboSampleComponent);
fix.detectChanges();
const combo = fix.componentInstance.combo;
combo.selectItems([], false);
expect(combo.selectedItems()).toEqual([]);
combo.selectItems([], true);
expect(combo.selectedItems()).toEqual([]);
const selectedItems = combo.data.slice(0, 3);
combo.selectItems(combo.data.slice(0, 3), true);
expect(combo.selectedItems()).toEqual(selectedItems);
combo.selectItems([], false);
expect(combo.selectedItems()).toEqual(selectedItems);
selectedItems.push(combo.data[3]);
combo.selectItems([combo.data[3]], false);
expect(combo.selectedItems()).toEqual(combo.data.slice(0, 4));
combo.selectItems([], true);
expect(combo.selectedItems()).toEqual([]);
}));

it('Should properly select/deselect ALL items', fakeAsync(() => {
const fix = TestBed.createComponent(IgxComboSampleComponent);
fix.detectChanges();
Expand Down
2 changes: 2 additions & 0 deletions projects/igniteui-angular/src/lib/core/selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ export class IgxSelectionAPIService {
let selection: Set<any>;
if (clearSelection) {
selection = this.get_empty();
} else if (itemIDs && itemIDs.length === 0) {
selection = new Set(this.get(componentID));
}
itemIDs.forEach((item) => selection = this.add_item(componentID, item, selection));
return selection;
Expand Down

0 comments on commit 4755c24

Please sign in to comment.