2

I would like to understand how to apply CSS for the existing PrimeNG autoComplete component.

The change I am looking for is, the input text color should be white.

HTML file (top-bar.component.html)

<p-autoComplete styleClass="myclass" [(ngModel)]="brand" [suggestions]="filteredBrands" (completeMethod)="filterBrands($event)" [size]="20" [minLength]="1"
      placeholder="Search" [dropdown]="true" (keyup.enter)="populateResults($event)">
    </p-autoComplete>

CSS class (top-bar.component.css)

.myclass .ui-autocomplete .ui-autocomplete-input {
  color: white;
}

Component class (top-bar.component.ts)

@Component({
  selector: 'app-top-bar',
  templateUrl: './top-bar.component.html',
  styleUrls: ['./top-bar.component.css']
})

Can someone help me on this ?

Thanks

Antikhippe
  • 6,316
  • 2
  • 28
  • 43
Rama Krishna. G
  • 526
  • 2
  • 8
  • 24
  • have a look at this [**answer**](https://stackoverflow.com/questions/40131174/what-is-best-way-to-override-the-style-of-primeng-components/43552505#43552505) – Aravind Apr 12 '18 at 07:12
  • 1
    I think what you're looking for is `[inputStyle]="{'color': 'white'}"`. If multiple styles need to be applied, `inputStyleClass` is even more convenient way. Refer to this docs https://www.primefaces.org/primeng-6.1.6/#/autocomplete – Ani Naslyan Jun 23 '20 at 08:10

3 Answers3

6

I could fix it from the @Aravind suggest link. Removed the styleClass from and modifed the css with :host >>>.

If the css file is of type scss then use ::ng-deep

HTML file (top-bar.component.html)

<p-autoComplete [(ngModel)]="brand" [suggestions]="filteredBrands" (completeMethod)="filterBrands($event)" [size]="20" [minLength]="1"
      placeholder="Search" [dropdown]="true" (keyup.enter)="populateResults($event)">
    </p-autoComplete>

CSS class (top-bar.component.css)

:host >>> .ui-autocomplete .ui-autocomplete-input {
  color: white;
}

IF SCSS class (top-bar.component.scss)

:host ::ng-deep .ui-autocomplete .ui-autocomplete-input {
  color: white;
}

Component class (top-bar.component.ts)

@Component({
  selector: 'app-top-bar',
  templateUrl: './top-bar.component.html',
  styleUrls: ['./top-bar.component.css']
})
Rama Krishna. G
  • 526
  • 2
  • 8
  • 24
0

Please try this CSS :

.ui-autocomplete>.ui-inputtext {
  color: white;
}

See Plunker

Antikhippe
  • 6,316
  • 2
  • 28
  • 43
0

Prime ng Autocomplete custom style

<p-autoComplete 
      [(ngModel)]="selectedMenu" 
      [suggestions]="filteredMenus" 
      (completeMethod)="filterMenu($event)"
      field="value_en" 
      [minLength]="3"
      (onSelect)="itemSelectEvent($event)"
      placeholder="Search Menu ..."
      size="50"
      [style]="{
        display: 'inline-flex',
        height: '34px'
      }"
      >
    </p-autoComplete>  

size="50" indicates the input width size