Skip to content

Commit 773c36b

Browse files
Merge pull request #14546 from IgniteUI/ganastasov/fix-14539-master
fix(combo): resolve error in dropdown component by setting id - master
2 parents 9097547 + 48c1d39 commit 773c36b

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ export abstract class IgxComboBaseDirective implements IgxComboBase, AfterViewCh
180180
if (selection) {
181181
this.selectionService.set(this._id, selection);
182182
}
183-
if (this.dropdown.open) {
183+
if (this.dropdown?.open) {
184184
this.dropdown.close();
185185
}
186186
if (this.inputGroup?.isFocused) {

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

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,6 +1340,22 @@ describe('igxCombo', () => {
13401340
caseSensitiveIcon = fixture.debugElement.query(By.css('igx-icon[name=\'case-sensitive\']'));
13411341
expect(caseSensitiveIcon).toBeNull();
13421342
});
1343+
it('should render the combo component with the id set and not throw an error', () => {
1344+
fixture = TestBed.createComponent(ComboWithIdComponent);
1345+
fixture.detectChanges();
1346+
1347+
combo = fixture.componentInstance.combo;
1348+
fixture.detectChanges();
1349+
1350+
expect(combo).toBeTruthy();
1351+
expect(combo.id).toEqual("id1");
1352+
fixture.detectChanges();
1353+
1354+
const errorSpy = spyOn(console, 'error');
1355+
fixture.detectChanges();
1356+
1357+
expect(errorSpy).not.toHaveBeenCalled();
1358+
});
13431359
});
13441360
describe('Positioning tests: ', () => {
13451361
let containerElement: any;
@@ -4032,3 +4048,32 @@ export class ComboArrayTypeValueKeyComponent {
40324048
];
40334049
}
40344050
}
4051+
4052+
@Component({
4053+
template: `
4054+
<igx-combo id="id1" [data]="items" valueKey="value" displayKey="item"></igx-combo>`,
4055+
standalone: true,
4056+
imports: [IgxComboComponent]
4057+
})
4058+
export class ComboWithIdComponent {
4059+
@ViewChild(IgxComboComponent, { read: IgxComboComponent, static: true })
4060+
public combo: IgxComboComponent;
4061+
public items: any[] = [];
4062+
4063+
constructor() {
4064+
this.items = [
4065+
{
4066+
item: "Item1",
4067+
value: "Option1"
4068+
},
4069+
{
4070+
item: "Item2",
4071+
value: "Option2"
4072+
},
4073+
{
4074+
item: "Item3",
4075+
value: "Option3",
4076+
}
4077+
];
4078+
}
4079+
}

0 commit comments

Comments
 (0)