Skip to content

Commit 59b9af5

Browse files
authored
Merge pull request #10500 from IgniteUI/bpenkov/combo-edit
Handle clear w/o valueKey
2 parents 5425c65 + ef2b00a commit 59b9af5

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,21 @@ describe('IgxSimpleCombo', () => {
386386
fixture.detectChanges();
387387
expect(component.selectedItem).toEqual(combo.data[4]);
388388
}));
389+
390+
it('should clear selection w/o valueKey', fakeAsync(() => {
391+
fixture = TestBed.createComponent(ComboModelBindingComponent);
392+
fixture.detectChanges();
393+
const component = fixture.componentInstance;
394+
combo = fixture.componentInstance.combo;
395+
component.items = ['One', 'Two', 'Three', 'Four', 'Five'];
396+
combo.select('Three');
397+
fixture.detectChanges();
398+
expect(combo.selection).toEqual(['Three']);
399+
combo.handleClear(new MouseEvent('click'));
400+
fixture.detectChanges();
401+
expect(combo.value).toEqual('');
402+
}));
403+
389404
it('should properly bind to values w/o valueKey', fakeAsync(() => {
390405
fixture = TestBed.createComponent(ComboModelBindingComponent);
391406
fixture.detectChanges();

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ export class IgxSimpleComboComponent extends IgxComboBaseDirective implements Co
370370
if (this._updateInput) {
371371
this.comboInput.value = this._value = displayText !== args.displayText
372372
? args.displayText
373-
: this.createDisplayText([args.newSelection], [args.oldSelection]);
373+
: this.createDisplayText(argsSelection, [args.oldSelection]);
374374
}
375375
this._onChangeCallback(args.newSelection);
376376
this._updateInput = true;
@@ -382,9 +382,12 @@ export class IgxSimpleComboComponent extends IgxComboBaseDirective implements Co
382382
return this.getRemoteSelection(newSelection, oldSelection);
383383
}
384384

385-
return this.displayKey !== null && this.displayKey !== undefined
386-
? this.convertKeysToItems(newSelection).map(e => e[this.displayKey])[0]
387-
: newSelection[0];
385+
if (this.displayKey !== null && this.displayKey !== undefined
386+
&& newSelection.length > 0) {
387+
return this.convertKeysToItems(newSelection).map(e => e[this.displayKey])[0];
388+
}
389+
390+
return newSelection[0] || '';
388391
}
389392

390393
private clearSelection(ignoreFilter?: boolean): void {

0 commit comments

Comments
 (0)