Skip to content

Commit 766e5e9

Browse files
fix(drop-down): ensure id attribute is set correctly when using bracket syntax
1 parent 1f753a2 commit 766e5e9

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

projects/igniteui-angular/src/lib/drop-down/drop-down.base.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export abstract class IgxDropDownBaseDirective implements IDropDownList, OnInit
7474
* <igx-drop-down [id]='newDropDownId'></igx-drop-down>
7575
* ```
7676
*/
77+
@HostBinding('attr.id')
7778
@Input()
7879
public get id(): string {
7980
return this._id;

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

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ describe('igxSelect', () => {
9898
IgxSelectReactiveFormComponent,
9999
IgxSelectTemplateFormComponent,
100100
IgxSelectHeaderFooterComponent,
101-
IgxSelectCDRComponent
101+
IgxSelectCDRComponent,
102+
IgxSelectWithIdComponent
102103
]
103104
}).compileComponents();
104105
}));
@@ -515,6 +516,21 @@ describe('igxSelect', () => {
515516
expect(dummyInput).toEqual(document.activeElement);
516517
expect(select.collapsed).toBeFalsy();
517518
}));
519+
520+
it('should set the id attribute when using property binding', () => {
521+
fixture = TestBed.createComponent(IgxSelectWithIdComponent);
522+
fixture.detectChanges();
523+
524+
select = fixture.componentInstance.select;
525+
fixture.detectChanges();
526+
527+
const selectElement = fixture.debugElement.query(By.css('igx-select')).nativeElement;
528+
fixture.detectChanges();
529+
530+
expect(select).toBeTruthy();
531+
expect(select.id).toEqual("id1");
532+
expect(selectElement.getAttribute('id')).toBe('id1');
533+
});
518534
});
519535

520536
describe('Form tests: ', () => {
@@ -3091,3 +3107,21 @@ class IgxSelectCDRComponent {
30913107
{ field: 'ContactName', type: 'string' }
30923108
];
30933109
}
3110+
3111+
@Component({
3112+
template: `
3113+
<igx-select [id]="'id1'">
3114+
<igx-select-item *ngFor="let item of items" [value]="item">
3115+
{{item}}
3116+
</igx-select-item>
3117+
</igx-select>
3118+
`,
3119+
standalone: true,
3120+
imports: [NgIf, IgxSelectComponent, IgxSelectItemComponent, IgxLabelDirective, NgFor]
3121+
})
3122+
class IgxSelectWithIdComponent {
3123+
@ViewChild(IgxSelectComponent, { read: IgxSelectComponent, static: true })
3124+
public select: IgxSelectComponent;
3125+
3126+
public items: string[] = ['Item 1', 'Item 2', 'Item 3', 'Item 4', 'Item 5'];
3127+
}

0 commit comments

Comments
 (0)