diff --git a/packages/primeng/src/inputicon/inputicon.spec.ts b/packages/primeng/src/inputicon/inputicon.spec.ts new file mode 100755 index 00000000000..f8a856d11dc --- /dev/null +++ b/packages/primeng/src/inputicon/inputicon.spec.ts @@ -0,0 +1,36 @@ +import { ComponentRef } from '@angular/core'; +import { TestBed, ComponentFixture } from '@angular/core/testing'; +import { InputIcon } from './inputicon'; +import { NoopAnimationsModule } from '@angular/platform-browser/animations'; + +describe('InputIcon', () => { + let inputIcon: InputIcon; + let fixture: ComponentFixture; + let inputIconRef: ComponentRef; + + beforeEach(() => { + TestBed.configureTestingModule({ imports: [NoopAnimationsModule, InputIcon] }); + fixture = TestBed.createComponent(InputIcon); + inputIcon = fixture.componentInstance; + inputIconRef = fixture.componentRef; + }); + + it('should create the component', () => { + expect(inputIcon).toBeTruthy(); + }); + + it('should always have the p-inputicon class by default', () => { + fixture.detectChanges(); + + expect(fixture.nativeElement.classList).toContain('p-inputicon'); + }); + + it('should apply custom classes from styleClass input', () => { + inputIconRef.setInput('styleClass', 'custom-class'); + fixture.detectChanges(); + + const inputIconHostElement = fixture.nativeElement; + expect(inputIconHostElement.classList).toContain('custom-class'); + expect(inputIconHostElement.classList).toContain('p-inputicon'); + }); +}); diff --git a/packages/primeng/src/inputicon/inputicon.ts b/packages/primeng/src/inputicon/inputicon.ts index 64ea7e6159a..8c990182d23 100755 --- a/packages/primeng/src/inputicon/inputicon.ts +++ b/packages/primeng/src/inputicon/inputicon.ts @@ -1,5 +1,4 @@ -import { CommonModule } from '@angular/common'; -import { ChangeDetectionStrategy, Component, HostBinding, inject, Input, NgModule, ViewEncapsulation } from '@angular/core'; +import { ChangeDetectionStrategy, Component, inject, input, NgModule, ViewEncapsulation } from '@angular/core'; import { SharedModule } from 'primeng/api'; import { BaseComponent } from 'primeng/basecomponent'; import { InputIconStyle } from './style/inputiconstyle'; @@ -11,13 +10,13 @@ import { InputIconStyle } from './style/inputiconstyle'; @Component({ selector: 'p-inputicon, p-inputIcon', standalone: true, - imports: [CommonModule, SharedModule], + imports: [SharedModule], template: ``, encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, providers: [InputIconStyle], host: { - '[class]': 'styleClass', + '[class]': 'styleClass()', '[class.p-inputicon]': 'true' } }) @@ -26,11 +25,7 @@ export class InputIcon extends BaseComponent { * Style class of the element. * @group Props */ - @Input() styleClass: string | undefined; - - @HostBinding('class') get hostClasses(): string { - return this.styleClass; - } + styleClass = input(); _componentStyle = inject(InputIconStyle); }