Skip to content

Commit 5b4a4e1

Browse files
authored
fix(combos): selection event consistent data items, value args (#13619)
Rename existing `newSelection` and `oldSelection` to `newValue` and `oldValue` respectively. Add new args in their place that emit data items consistently regardless of `valueKey`. For `IgxCombo` also update `added` and `removed` collections to always contain data items
1 parent ad5e49e commit 5b4a4e1

File tree

8 files changed

+311
-71
lines changed

8 files changed

+311
-71
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,17 @@ All notable changes for each version of this project will be documented in this
1717
- We're working on reducing the library size
1818
- IgxRadioComponent has been reduced in half
1919
- IgxSwitchComponent has been reduced in half
20+
- `IgxCombo`
21+
- **Breaking Change** `IComboSelectionChangingEventArgs` properties `newSelection` and `oldSelection` have been renamed to `newValue` and `oldValue` respectively to better reflect their function. Just like Combo's `value`, those will emit either the specified property values or full data items depending on whether `valueKey` is set or not. Automatic migrations are available and will be applied on `ng update`.
22+
- `IComboSelectionChangingEventArgs` exposes two new properties `newSelection` and `oldSelection` in place of the old ones that are no longer affected by `valueKey` and consistently emit items from Combo's `data`.
23+
24+
Note: In remote data scenarios with `valueKey` set, selected items that are not currently part of the loaded data chunk will be emitted a partial item data object with the `valueKey` property.
25+
- **Breaking Change** - `IComboSelectionChangingEventArgs` properties `added` and `removed` now always contain data items, regardless of `valueKey` being set. This aligns them with the updated `newSelection` and `oldSelection` properties, including the same limitation for remote data as described above.
26+
- `IgxSimpleCombo`
27+
- **Breaking Change** - `ISimpleComboSelectionChangingEventArgs` properties `newSelection` and `oldSelection` have been renamed to `newValue` and `oldValue` respectively to better reflect their function. Just like Combo's `value`, those will emit either the specified property value or full data item depending on whether `valueKey` is set or not. Automatic migrations are available and will be applied on `ng update`.
28+
- `ISimpleComboSelectionChangingEventArgs` exposes two new properties `newSelection` and `oldSelection` in place of the old ones that are no longer affected by `valueKey` and consistently emit items from Combo's `data`.
2029

30+
Note: In remote data scenarios with `valueKey` set, selected items that are not currently part of the loaded data chunk will be emitted a partial item data object with the `valueKey` property.
2131
## 16.1.4
2232
### New Features
2333
- `Themes`:
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"$schema": "../../common/schema/members-changes.schema.json",
3+
"changes": [
4+
{
5+
"member": "newSelection",
6+
"replaceWith": "newValue",
7+
"definedIn": [
8+
"IComboSelectionChangingEventArgs",
9+
"ISimpleComboSelectionChangingEventArgs"
10+
]
11+
},
12+
{
13+
"member": "oldSelection",
14+
"replaceWith": "oldValue",
15+
"definedIn": [
16+
"IComboSelectionChangingEventArgs",
17+
"ISimpleComboSelectionChangingEventArgs"
18+
]
19+
}
20+
]
21+
}

projects/igniteui-angular/migrations/update-17_0_0/index.spec.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,66 @@ describe(`Update to ${version}`, () => {
206206
);
207207
});
208208

209+
it('Should properly rename newSelection and oldSelection property to newValue and oldValue in Combo', async () => {
210+
pending('set up tests for migrations through lang service');
211+
appTree.create('/testSrc/appPrefix/component/test.component.ts',
212+
`
213+
import { IgxComboComponent, IComboSelectionChangingEventArgs } from 'igniteui-angular';
214+
export class MyClass {
215+
public handleSelectionChanging(e: IComboSelectionChangingEventArgs) {
216+
const newSelection = e.newSelection;
217+
const oldSelection = e.oldSelection;
218+
}
219+
}
220+
`);
221+
222+
const tree = await schematicRunner.runSchematic(migrationName, {}, appTree);
223+
224+
expect(
225+
tree.readContent('/testSrc/appPrefix/component/test.component.ts')
226+
).toEqual(
227+
`
228+
import { IgxComboComponent, IComboSelectionChangingEventArgs } from 'igniteui-angular';
229+
export class MyClass {
230+
public handleSelectionChanging(e: IComboSelectionChangingEventArgs) {
231+
const newSelection = e.newValue;
232+
const oldSelection = e.oldValue;
233+
}
234+
}
235+
`
236+
);
237+
});
238+
239+
it('Should properly rename newSelection and oldSelection property to newValue and oldValue SimpleCombo', async () => {
240+
pending('set up tests for migrations through lang service');
241+
appTree.create('/testSrc/appPrefix/component/test.component.ts',
242+
`
243+
import { IgxSimpleComboComponent, ISimpleComboSelectionChangingEventArgs } from 'igniteui-angular';
244+
export class MyClass {
245+
public handleSelectionChanging(e: ISimpleComboSelectionChangingEventArgs) {
246+
const newSelection = e.newSelection;
247+
const oldSelection = e.oldSelection;
248+
}
249+
}
250+
`);
251+
252+
const tree = await schematicRunner.runSchematic(migrationName, {}, appTree);
253+
254+
expect(
255+
tree.readContent('/testSrc/appPrefix/component/test.component.ts')
256+
).toEqual(
257+
`
258+
import { IgxComboComponent, IComboSelectionChangingEventArgs } from 'igniteui-angular';
259+
export class MyClass {
260+
public handleSelectionChanging(e: IComboSelectionChangingEventArgs) {
261+
const newSelection = e.newValue;
262+
const oldSelection = e.oldValue;
263+
}
264+
}
265+
`
266+
);
267+
});
268+
209269
for (const igPackage of ['igniteui-angular', '@infragistics/igniteui-angular']) {
210270
it('should move animation imports from igniteui-angular to igniteui-angular/animations', async () => {
211271
appTree.create(`/testSrc/appPrefix/component/test.component.ts`,

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,11 +1295,13 @@ export abstract class IgxComboBaseDirective extends DisplayDensityBase implement
12951295
return keys;
12961296
}
12971297

1298-
// map keys vs. filter data to retain the order of the selected items
1299-
return keys.map(key => isNaNvalue(key)
1300-
? this.data.find(entry => isNaNvalue(entry[this.valueKey]))
1301-
: this.data.find(entry => entry[this.valueKey] === key))
1302-
.filter(e => e !== undefined);
1298+
return keys.map(key => {
1299+
const item = isNaNvalue(key)
1300+
? this.data.find(entry => isNaNvalue(entry[this.valueKey]))
1301+
: this.data.find(entry => entry[this.valueKey] === key);
1302+
1303+
return item !== undefined ? item : { [this.valueKey]: key };
1304+
});
13031305
}
13041306

13051307
protected checkMatch(): void {

0 commit comments

Comments
 (0)