Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does mat-autocomplete classList Input work?

According to the MatAutocomplete documentation, there is a classList input to style the panel.

@Input('class') classList: string | string[]

Takes classes set on the host mat-autocomplete element and applies them to the panel inside the overlay container to allow for easy styling.

When I do <mat-autocomplete #auto="matAutocomplete" classList="test-class"> I expected that I would see the test-class added to the mat-autocomplete-panel? But this does not work.

Can someone please explain how this input is to be used?

Stackblitz

like image 286
Pieter Buys Avatar asked Aug 26 '26 16:08

Pieter Buys


1 Answers

I figured it out. The docs say that it takes classes "set on the host mat-autocomplete".

That's the part I missed. You need to set class="test-class" as well

<mat-autocomplete #auto="matAutocomplete" class = "test-class" classlist="test-class">

I also realized that the css must be in your app's base styles.css file and not in your component css file for it to work. It's probably because your panel will be inside an overlay outside of your component

Working stackblitz

Edit

OR as Ankit Singh pointed out in his answer, you can use ::ng-deep if you still want to do it in the component css file...

::ng-deep .test-class {
  background-color: blue;
}
like image 185
Pieter Buys Avatar answered Aug 29 '26 07:08

Pieter Buys



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!