@@ -1966,6 +1966,31 @@ describe('MatAutocomplete', () => {
1966
1966
expect ( panel . classList ) . toContain ( 'class-two' ) ;
1967
1967
} ) ) ;
1968
1968
1969
+ it ( 'should remove old classes when the panel class changes' , fakeAsync ( ( ) => {
1970
+ const fixture = createComponent ( SimpleAutocomplete ) ;
1971
+ fixture . detectChanges ( ) ;
1972
+
1973
+ fixture . componentInstance . trigger . openPanel ( ) ;
1974
+ tick ( ) ;
1975
+ fixture . detectChanges ( ) ;
1976
+
1977
+ const classList =
1978
+ overlayContainerElement . querySelector ( '.mat-autocomplete-panel' ) ! . classList ;
1979
+
1980
+ expect ( classList ) . toContain ( 'mat-autocomplete-visible' ) ;
1981
+ expect ( classList ) . toContain ( 'class-one' ) ;
1982
+ expect ( classList ) . toContain ( 'class-two' ) ;
1983
+
1984
+ fixture . componentInstance . panelClass = 'class-three class-four' ;
1985
+ fixture . detectChanges ( ) ;
1986
+
1987
+ expect ( classList ) . not . toContain ( 'class-one' ) ;
1988
+ expect ( classList ) . not . toContain ( 'class-two' ) ;
1989
+ expect ( classList ) . toContain ( 'mat-autocomplete-visible' ) ;
1990
+ expect ( classList ) . toContain ( 'class-three' ) ;
1991
+ expect ( classList ) . toContain ( 'class-four' ) ;
1992
+ } ) ) ;
1993
+
1969
1994
it ( 'should reset correctly when closed programmatically' , fakeAsync ( ( ) => {
1970
1995
const scrolledSubject = new Subject ( ) ;
1971
1996
const fixture = createComponent ( SimpleAutocomplete , [
@@ -2307,7 +2332,7 @@ describe('MatAutocomplete', () => {
2307
2332
[formControl]="stateCtrl">
2308
2333
</mat-form-field>
2309
2334
2310
- <mat-autocomplete class="class-one class-two " #auto="matAutocomplete" [displayWith]="displayFn"
2335
+ <mat-autocomplete [ class]="panelClass " #auto="matAutocomplete" [displayWith]="displayFn"
2311
2336
[disableRipple]="disableRipple" (opened)="openedSpy()" (closed)="closedSpy()">
2312
2337
<mat-option *ngFor="let state of filteredStates" [value]="state">
2313
2338
<span>{{ state.code }}: {{ state.name }}</span>
@@ -2323,6 +2348,7 @@ class SimpleAutocomplete implements OnDestroy {
2323
2348
width : number ;
2324
2349
disableRipple = false ;
2325
2350
autocompleteDisabled = false ;
2351
+ panelClass = 'class-one class-two' ;
2326
2352
openedSpy = jasmine . createSpy ( 'autocomplete opened spy' ) ;
2327
2353
closedSpy = jasmine . createSpy ( 'autocomplete closed spy' ) ;
2328
2354
@@ -2361,7 +2387,6 @@ class SimpleAutocomplete implements OnDestroy {
2361
2387
ngOnDestroy ( ) {
2362
2388
this . valueSub . unsubscribe ( ) ;
2363
2389
}
2364
-
2365
2390
}
2366
2391
2367
2392
@Component ( {
0 commit comments