Skip to content

Commit

Permalink
Merge pull request #10500 from IgniteUI/bpenkov/combo-edit
Browse files Browse the repository at this point in the history
Handle clear w/o valueKey
  • Loading branch information
Lipata authored Nov 15, 2021
2 parents 5425c65 + ef2b00a commit 59b9af5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,21 @@ describe('IgxSimpleCombo', () => {
fixture.detectChanges();
expect(component.selectedItem).toEqual(combo.data[4]);
}));

it('should clear selection w/o valueKey', fakeAsync(() => {
fixture = TestBed.createComponent(ComboModelBindingComponent);
fixture.detectChanges();
const component = fixture.componentInstance;
combo = fixture.componentInstance.combo;
component.items = ['One', 'Two', 'Three', 'Four', 'Five'];
combo.select('Three');
fixture.detectChanges();
expect(combo.selection).toEqual(['Three']);
combo.handleClear(new MouseEvent('click'));
fixture.detectChanges();
expect(combo.value).toEqual('');
}));

it('should properly bind to values w/o valueKey', fakeAsync(() => {
fixture = TestBed.createComponent(ComboModelBindingComponent);
fixture.detectChanges();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ export class IgxSimpleComboComponent extends IgxComboBaseDirective implements Co
if (this._updateInput) {
this.comboInput.value = this._value = displayText !== args.displayText
? args.displayText
: this.createDisplayText([args.newSelection], [args.oldSelection]);
: this.createDisplayText(argsSelection, [args.oldSelection]);
}
this._onChangeCallback(args.newSelection);
this._updateInput = true;
Expand All @@ -382,9 +382,12 @@ export class IgxSimpleComboComponent extends IgxComboBaseDirective implements Co
return this.getRemoteSelection(newSelection, oldSelection);
}

return this.displayKey !== null && this.displayKey !== undefined
? this.convertKeysToItems(newSelection).map(e => e[this.displayKey])[0]
: newSelection[0];
if (this.displayKey !== null && this.displayKey !== undefined
&& newSelection.length > 0) {
return this.convertKeysToItems(newSelection).map(e => e[this.displayKey])[0];
}

return newSelection[0] || '';
}

private clearSelection(ignoreFilter?: boolean): void {
Expand Down

0 comments on commit 59b9af5

Please sign in to comment.