Skip to content

Commit 7b25e62

Browse files
authored
Merge pull request #2442 from IgniteUI/vslavov/combo-selectionChange-emit-master
IgxCombo - Selection - Override Selection through onSelectionChange emit - 6.2
2 parents 06c736c + ac3d7b3 commit 7b25e62

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

projects/igniteui-angular/src/lib/combo/combo.component.spec.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1481,6 +1481,27 @@ describe('igxCombo', () => {
14811481
expectedOutput += ', ' + combo.data[9];
14821482
expect(inputElement.value).toEqual(expectedOutput);
14831483
}));
1484+
1485+
it('Should properly handle selection manipulation through onSelectionChange emit', fakeAsync(() => {
1486+
const fixture = TestBed.createComponent(IgxComboSampleComponent);
1487+
fixture.detectChanges();
1488+
const combo = fixture.componentInstance.combo;
1489+
// override selection
1490+
fixture.componentInstance.onSelectionChange = (event) => {
1491+
event.newSelection = [];
1492+
};
1493+
combo.toggle();
1494+
tick();
1495+
// No items are initially selected
1496+
expect(combo.selectedItems()).toEqual([]);
1497+
// Select the first 5 items
1498+
combo.selectItems(fixture.componentInstance.initData.splice(0, 5));
1499+
tick();
1500+
fixture.detectChanges();
1501+
tick();
1502+
// onSelectionChange fires and overrides the selection to be [];
1503+
expect(combo.selectedItems()).toEqual([]);
1504+
}));
14841505
});
14851506

14861507
describe('Rendering tests: ', () => {
@@ -3057,7 +3078,8 @@ class IgxComboScrollTestComponent {
30573078
@Component({
30583079
template: `
30593080
<igx-combo #combo [placeholder]="'Location'" [data]='items'
3060-
[filterable]='true' [valueKey]="'field'" [groupKey]="'region'" [width]="'400px'" [allowCustomValues]="true">
3081+
[filterable]='true' [valueKey]="'field'" [groupKey]="'region'" [width]="'400px'"
3082+
(onSelectionChange)="onSelectionChange($event)" [allowCustomValues]="true">
30613083
<ng-template #itemTemplate let-display let-key="valueKey">
30623084
<div class="state-card--simple">
30633085
<span class="small-red-circle"></span>

projects/igniteui-angular/src/lib/combo/combo.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,8 +1065,8 @@ export class IgxComboComponent implements AfterViewInit, ControlValueAccessor, O
10651065
const args: IComboSelectionChangeEventArgs = { oldSelection, newSelection };
10661066
this.onSelectionChange.emit(args);
10671067
newSelectionAsSet = new Set();
1068-
for (let i = 0; i < newSelection.length; i++) {
1069-
newSelectionAsSet.add(newSelection[i]);
1068+
for (let i = 0; i < args.newSelection.length; i++) {
1069+
newSelectionAsSet.add(args.newSelection[i]);
10701070
}
10711071
this.selectionAPI.set_selection(this.id, newSelectionAsSet);
10721072
this.value = this.dataType !== DataTypes.PRIMITIVE ?

0 commit comments

Comments
 (0)