Skip to content

Commit 0b7b0b9

Browse files
fix(simple-combo): create display text only if there is bound data #12269 (#12279)
1 parent c14c5e1 commit 0b7b0b9

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,8 @@ describe('IgxSimpleCombo', () => {
432432
beforeAll(waitForAsync(() => {
433433
TestBed.configureTestingModule({
434434
declarations: [
435-
IgxSimpleComboSampleComponent
435+
IgxSimpleComboSampleComponent,
436+
IgxSimpleComboEmptyComponent
436437
],
437438
imports: [
438439
IgxSimpleComboModule,
@@ -631,6 +632,13 @@ describe('IgxSimpleCombo', () => {
631632
expect(footerHTMLElement.parentNode).toEqual(dropdownList);
632633
expect(footerHTMLElement.textContent).toEqual('This is a footer');
633634
});
635+
it('should initialize the component with empty data and bindings', () => {
636+
fixture = TestBed.createComponent(IgxSimpleComboEmptyComponent);
637+
expect(() => {
638+
fixture.detectChanges();
639+
}).not.toThrow();
640+
expect(fixture.componentInstance.combo).toBeDefined();
641+
});
634642
});
635643

636644
describe('Binding tests: ', () => {
@@ -1852,6 +1860,17 @@ class IgxSimpleComboSampleComponent {
18521860
}
18531861
}
18541862

1863+
@Component({
1864+
template: `<igx-simple-combo #combo [data]="data" displayKey="test" [(ngModel)]="name"></igx-simple-combo>`
1865+
})
1866+
export class IgxSimpleComboEmptyComponent {
1867+
@ViewChild('combo', { read: IgxSimpleComboComponent, static: true })
1868+
public combo: IgxSimpleComboComponent;
1869+
1870+
public data: any[] = [];
1871+
public name!: string;
1872+
}
1873+
18551874
@Component({
18561875
template: `<igx-simple-combo [(ngModel)]="selectedItem" [data]="items"></igx-simple-combo>`
18571876
})

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,9 +455,10 @@ export class IgxSimpleComboComponent extends IgxComboBaseDirective implements Co
455455
return this.getRemoteSelection(newSelection, oldSelection);
456456
}
457457

458-
if (this.displayKey !== null && this.displayKey !== undefined
458+
if (this.displayKey !== null
459+
&& this.displayKey !== undefined
459460
&& newSelection.length > 0) {
460-
return this.convertKeysToItems(newSelection).map(e => e[this.displayKey])[0]?.toString() || '';
461+
return this.convertKeysToItems(newSelection).filter(e => e).map(e => e[this.displayKey])[0]?.toString() || '';
461462
}
462463

463464
return newSelection[0]?.toString() || '';

0 commit comments

Comments
 (0)