Skip to content

Commit b4defff

Browse files
fix(drop-down): ensure id attribute is set correctly when using bracket syntax
1 parent 83bc2a8 commit b4defff

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
@@ -71,6 +71,7 @@ export abstract class IgxDropDownBaseDirective extends DisplayDensityBase implem
7171
* <igx-drop-down [id]='newDropDownId'></igx-drop-down>
7272
* ```
7373
*/
74+
@HostBinding('attr.id')
7475
@Input()
7576
public get id(): string {
7677
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
@@ -99,7 +99,8 @@ describe('igxSelect', () => {
9999
IgxSelectReactiveFormComponent,
100100
IgxSelectTemplateFormComponent,
101101
IgxSelectHeaderFooterComponent,
102-
IgxSelectCDRComponent
102+
IgxSelectCDRComponent,
103+
IgxSelectWithIdComponent
103104
]
104105
}).compileComponents();
105106
}));
@@ -532,6 +533,21 @@ describe('igxSelect', () => {
532533
expect(dummyInput).toEqual(document.activeElement);
533534
expect(select.collapsed).toBeFalsy();
534535
}));
536+
537+
it('should set the id attribute when using property binding', () => {
538+
fixture = TestBed.createComponent(IgxSelectWithIdComponent);
539+
fixture.detectChanges();
540+
541+
select = fixture.componentInstance.select;
542+
fixture.detectChanges();
543+
544+
const selectElement = fixture.debugElement.query(By.css('igx-select')).nativeElement;
545+
fixture.detectChanges();
546+
547+
expect(select).toBeTruthy();
548+
expect(select.id).toEqual("id1");
549+
expect(selectElement.getAttribute('id')).toBe('id1');
550+
});
535551
});
536552

537553
describe('Form tests: ', () => {
@@ -3107,3 +3123,21 @@ class IgxSelectCDRComponent {
31073123
{ field: 'ContactName', type: 'string' }
31083124
];
31093125
}
3126+
3127+
@Component({
3128+
template: `
3129+
<igx-select [id]="'id1'">
3130+
<igx-select-item *ngFor="let item of items" [value]="item">
3131+
{{item}}
3132+
</igx-select-item>
3133+
</igx-select>
3134+
`,
3135+
standalone: true,
3136+
imports: [NgIf, IgxSelectComponent, IgxSelectItemComponent, IgxLabelDirective, NgFor]
3137+
})
3138+
class IgxSelectWithIdComponent {
3139+
@ViewChild(IgxSelectComponent, { read: IgxSelectComponent, static: true })
3140+
public select: IgxSelectComponent;
3141+
3142+
public items: string[] = ['Item 1', 'Item 2', 'Item 3', 'Item 4', 'Item 5'];
3143+
}

0 commit comments

Comments
 (0)