Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(drop-down): ensure id attribute is set correctly when using bracket syntax - 18.1.x #14584

Merged
merged 2 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export abstract class IgxDropDownBaseDirective implements IDropDownList, OnInit
* <igx-drop-down [id]='newDropDownId'></igx-drop-down>
* ```
*/
@HostBinding('attr.id')
@Input()
public get id(): string {
return this._id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ describe('igxSelect', () => {
IgxSelectReactiveFormComponent,
IgxSelectTemplateFormComponent,
IgxSelectHeaderFooterComponent,
IgxSelectCDRComponent
IgxSelectCDRComponent,
IgxSelectWithIdComponent
]
}).compileComponents();
}));
Expand Down Expand Up @@ -515,6 +516,21 @@ describe('igxSelect', () => {
expect(dummyInput).toEqual(document.activeElement);
expect(select.collapsed).toBeFalsy();
}));

it('should set the id attribute when using property binding', () => {
fixture = TestBed.createComponent(IgxSelectWithIdComponent);
fixture.detectChanges();

select = fixture.componentInstance.select;
fixture.detectChanges();

const selectElement = fixture.debugElement.query(By.css('igx-select')).nativeElement;
fixture.detectChanges();

expect(select).toBeTruthy();
expect(select.id).toEqual("id1");
expect(selectElement.getAttribute('id')).toBe('id1');
});
});

describe('Form tests: ', () => {
Expand Down Expand Up @@ -3091,3 +3107,21 @@ class IgxSelectCDRComponent {
{ field: 'ContactName', type: 'string' }
];
}

@Component({
template: `
<igx-select [id]="'id1'">
<igx-select-item *ngFor="let item of items" [value]="item">
{{item}}
</igx-select-item>
</igx-select>
`,
standalone: true,
imports: [NgIf, IgxSelectComponent, IgxSelectItemComponent, IgxLabelDirective, NgFor]
})
class IgxSelectWithIdComponent {
@ViewChild(IgxSelectComponent, { read: IgxSelectComponent, static: true })
public select: IgxSelectComponent;

public items: string[] = ['Item 1', 'Item 2', 'Item 3', 'Item 4', 'Item 5'];
}
Loading