Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions projects/igniteui-angular/src/lib/combo/combo.common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { noop, Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { DisplayDensityBase, DisplayDensityToken, IDisplayDensityOptions } from '../core/density';
import { IgxSelectionAPIService } from '../core/selection';
import { CancelableBrowserEventArgs, cloneArray, IBaseCancelableBrowserEventArgs, IBaseEventArgs, isNaNvalue, rem } from '../core/utils';
import { CancelableBrowserEventArgs, cloneArray, IBaseCancelableBrowserEventArgs, IBaseEventArgs, rem } from '../core/utils';
import { SortingDirection } from '../data-operations/sorting-strategy';
import { IForOfState, IgxForOfDirective } from '../directives/for-of/for_of.directive';
import { IgxIconService } from '../icon/icon.service';
Expand All @@ -46,6 +46,7 @@ import {
import { IComboItemAdditionEvent, IComboSearchInputEventArgs } from './public_api';
import { ComboResourceStringsEN, IComboResourceStrings } from '../core/i18n/combo-resources';
import { getCurrentResourceStrings } from '../core/i18n/resources';
import { isEqual } from 'lodash-es';

export const IGX_COMBO_COMPONENT = /*@__PURE__*/new InjectionToken<IgxComboBase>('IgxComboComponentToken');

Expand Down Expand Up @@ -1282,9 +1283,7 @@ export abstract class IgxComboBaseDirective extends DisplayDensityBase implement
}

return keys.map(key => {
const item = isNaNvalue(key)
? this.data.find(entry => isNaNvalue(entry[this.valueKey]))
: this.data.find(entry => entry[this.valueKey] === key);
const item = this.data.find(entry => isEqual(entry[this.valueKey], key));

return item !== undefined ? item : { [this.valueKey]: key };
});
Expand Down
78 changes: 78 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 @@ -2342,6 +2342,55 @@ describe('igxCombo', () => {
expect(combo.value).toEqual([]);
expect(combo.displayValue).toEqual('Selected Count: 0');
});
it('should handle selection for combo with array type value key correctly - issue #14103', () => {
fixture = TestBed.createComponent(ComboArrayTypeValueKeyComponent);
fixture.detectChanges();
combo = fixture.componentInstance.combo;
input = fixture.debugElement.query(By.css(`.${CSS_CLASS_COMBO_INPUTGROUP}`));
const items = fixture.componentInstance.items;
expect(combo).toBeDefined();

const selectionSpy = spyOn(combo.selectionChanging, 'emit');
let expectedResults: IComboSelectionChangingEventArgs = {
newValue: [combo.data[1][combo.valueKey]],
oldValue: [],
newSelection: [combo.data[1]],
oldSelection: [],
added: [combo.data[1]],
removed: [],
event: undefined,
owner: combo,
displayText: `${combo.data[1][combo.displayKey]}`,
cancel: false
};

let expectedDisplayText = items[1][combo.displayKey];
combo.select([fixture.componentInstance.items[1].value]);
fixture.detectChanges();

expect(selectionSpy).toHaveBeenCalledWith(expectedResults);
expect(input.nativeElement.value).toEqual(expectedDisplayText);

expectedDisplayText = `${items[1][combo.displayKey]}, ${items[2][combo.displayKey]}`;
expectedResults = {
newValue: [combo.data[1][combo.valueKey], combo.data[2][combo.valueKey]],
oldValue: [combo.data[1][combo.valueKey]],
newSelection: [combo.data[1], combo.data[2]],
oldSelection: [combo.data[1]],
added: [combo.data[2]],
removed: [],
event: undefined,
owner: combo,
displayText: expectedDisplayText,
cancel: false
};

combo.select([items[2].value]);
fixture.detectChanges();

expect(selectionSpy).toHaveBeenCalledWith(expectedResults);
expect(input.nativeElement.value).toEqual(expectedDisplayText);
});
});
describe('Grouping tests: ', () => {
beforeEach(() => {
Expand Down Expand Up @@ -3797,3 +3846,32 @@ export class IgxComboBindingDataAfterInitComponent implements AfterViewInit {
}, 1000);
}
}

@Component({
template: `
<igx-combo [data]="items" valueKey="value" displayKey="item"></igx-combo>`,
standalone: true,
imports: [IgxComboComponent]
})
export class ComboArrayTypeValueKeyComponent {
@ViewChild(IgxComboComponent, { read: IgxComboComponent, static: true })
public combo: IgxComboComponent;
public items: any[] = [];

constructor() {
this.items = [
{
item: "Item1",
value: [1, 2, 3]
},
{
item: "Item2",
value: [4, 5, 6]
},
{
item: "Item3",
value: [7, 8, 9]
}
];
}
}
9 changes: 0 additions & 9 deletions projects/igniteui-angular/src/lib/core/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,15 +226,6 @@ export const isEqual = (obj1, obj2): boolean => {
return obj1 === obj2;
};

/**
* Checks if provided variable is the value NaN
*
* @param value Value to check
* @returns true if provided variable is NaN
* @hidden
*/
export const isNaNvalue = (value: any): boolean => isNaN(value) && value !== undefined && typeof value !== 'string';

/**
* Utility service taking care of various utility functions such as
* detecting browser features, general cross browser DOM manipulation, etc.
Expand Down