Skip to content

Commit 919f31e

Browse files
committed
chore(combo): move diffInSets definition to combo, update README.md
1 parent 86f2a7a commit 919f31e

File tree

4 files changed

+29
-43
lines changed

4 files changed

+29
-43
lines changed

CHANGELOG.md

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
All notable changes for each version of this project will be documented in this file.
44

5-
## 8.2.0
5+
## 8.1.3
66
- `IgxCombo`
77
- Combo `onSelectionChange` events now emits the item(s) that were added to or removed from the collection:
88
```html
@@ -11,44 +11,18 @@ All notable changes for each version of this project will be documented in this
1111
```typescript
1212
export class Example {
1313
...
14-
handleChange(event: {
15-
newSelection: any[],
16-
oldSelection: any[],
17-
added: any[], // the items added to the selection in this change
18-
removed: any[], // the items removed for the selection in this change
19-
...
20-
}) {
21-
console.log("Items added: ", [...event.added]);
22-
console.log("Items removed: ", [...event.removed]);
14+
handleChange(event: IComboSelectionChangeEventArgs) {
15+
console.log("Items added: ", [...event.added]); // the items added to the selection in this change
16+
console.log("Items removed: ", [...event.removed]); // the items removed from the selection in this change
2317
}
2418
}
2519
```
26-
20+
2721
## 8.1.2
2822

2923
### New Features
3024
- `IgxDatePicker`
3125
- `valueChange` event is added.
32-
- `IgxCombo`
33-
- Combo `onSelectionChange` events now emits the item(s) that were added to or removed from the collection:
34-
```html
35-
<igx-combo (onSelectionChange)="handleChange($event)">
36-
```
37-
```typescript
38-
export class Example {
39-
...
40-
handleChange(event: {
41-
newSelection: any[],
42-
oldSelection: any[],
43-
added: any[], // the items added to the selection in this change
44-
removed: any[], // the items removed for the selection in this change
45-
...
46-
}) {
47-
console.log("Items added: ", [...event.added]);
48-
console.log("Items removed: ", [...event.removed]);
49-
}
50-
}
51-
```
5226

5327
## 8.1.0
5428

projects/igniteui-angular/src/lib/combo/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ Setting `[displayDensity]` affects the control's items' and inputs' css properti
276276

277277
| Name | Description | Cancelable | Parameters |
278278
|------------------ |-------------------------------------------------------------------------|------------- |-----------------------------------------|
279-
| `onSelectionChange` | Emitted when item selection is changing, before the selection completes | true | { oldSelection: `any[]`, newSelection: `any[]`, event?: `Event`, added: `any[]`, removed: `any[]`, cancel: `boolean` } |
279+
| `onSelectionChange` | Emitted when item selection is changing, before the selection completes | true | [`IComboSelectionChangeEventArgs`](https://www.infragistics.com/products/ignite-ui-angular/docs/typescript/latest/interfaces/icomboselectionchangeeventargs.html) |
280280
| `onSearchInput` | Emitted when an the search input's input event is triggered | false | { searchValue: `string` } |
281281
| `onAddition` | Emitted when an item is being added to the data collection | false | { oldCollection: `any[]`, addedItem: `<any>`, newCollection: `any[]` }|
282282
| `onDataPreLoad` | Emitted when new chunk of data is loaded from the virtualization | false | { event: `Event` } |

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

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
import { FormsModule, ReactiveFormsModule, ControlValueAccessor, NG_VALUE_ACCESSOR, NgControl } from '@angular/forms';
1818
import { IgxCheckboxModule } from '../checkbox/checkbox.component';
1919
import { IgxSelectionAPIService } from '../core/selection';
20-
import { cloneArray, CancelableEventArgs, CancelableBrowserEventArgs, diffInSets } from '../core/utils';
20+
import { cloneArray, CancelableEventArgs, CancelableBrowserEventArgs } from '../core/utils';
2121
import { IgxStringFilteringOperand, IgxBooleanFilteringOperand } from '../data-operations/filtering-condition';
2222
import { FilteringLogic, IFilteringExpression } from '../data-operations/filtering-expression.interface';
2323
import { SortingDirection, ISortingExpression } from '../data-operations/sorting-expression.interface';
@@ -83,11 +83,17 @@ export enum IgxComboState {
8383
INVALID
8484
}
8585

86+
/** Event emitted when an igx-combo's selection is changing */
8687
export interface IComboSelectionChangeEventArgs extends CancelableEventArgs {
88+
/** An array containing the values that are currently selected */
8789
oldSelection: any[];
90+
/** An array containing the values that will be selected after this event */
8891
newSelection: any[];
92+
/** An array containing the values that will be added to the selection (if any) */
8993
added: any[];
94+
/** An array containing the values that will be removed from the selection (if any) */
9095
removed: any[];
96+
/** The user interaction that triggered the selection change */
9197
event?: Event;
9298
}
9399

@@ -97,6 +103,20 @@ export interface IComboItemAdditionEvent {
97103
newCollection: any[];
98104
}
99105

106+
/**
107+
* When called with sets A & B, returns A - B (as array);
108+
* @hidden
109+
*/
110+
function diffInSets(set1: Set<any>, set2: Set<any>): any[] {
111+
const results = [];
112+
set1.forEach(entry => {
113+
if (!set2.has(entry)) {
114+
results.push(entry);
115+
}
116+
});
117+
return results;
118+
}
119+
100120
let NEXT_ID = 0;
101121
const noop = () => { };
102122

@@ -1498,8 +1518,8 @@ export class IgxComboComponent extends DisplayDensityBase implements IgxComboBas
14981518
}
14991519

15001520
protected setSelection(newSelection: Set<any>, event?: Event): void {
1501-
const removed = Array.from(diffInSets(this.selection.get(this.id), newSelection));
1502-
const added = Array.from(diffInSets(newSelection, this.selection.get(this.id)));
1521+
const removed = diffInSets(this.selection.get(this.id), newSelection);
1522+
const added = diffInSets(newSelection, this.selection.get(this.id));
15031523
const oldSelectionEmit = Array.from(this.selection.get(this.id) || []);
15041524
const newSelectionEmit = Array.from(newSelection || []);
15051525
const args: IComboSelectionChangeEventArgs = {

projects/igniteui-angular/src/lib/core/utils.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,6 @@ export function cloneArray(array: any[], deep?: boolean) {
1313
return arr;
1414
}
1515

16-
/**
17-
* When called with sets A & B, returns A - B (as set);
18-
* @hidden
19-
*/
20-
export function diffInSets(set1: Set<any>, set2: Set<any>): Set<any> {
21-
return new Set(Array.from(set1).filter(entry => !set2.has(entry)));
22-
}
23-
2416
/**
2517
* Doesn't clone leaf items
2618
* @hidden

0 commit comments

Comments
 (0)