8
8
9
9
import { ActiveDescendantKeyManager } from '@angular/cdk/a11y' ;
10
10
import { BooleanInput , coerceBooleanProperty } from '@angular/cdk/coercion' ;
11
+ import { coerceArray } from '@angular/cdk/coercion/array' ;
11
12
import {
12
13
AfterContentInit ,
13
14
ChangeDetectionStrategy ,
@@ -75,6 +76,9 @@ const _MatAutocompleteMixinBase: CanDisableRippleCtor & typeof MatAutocompleteBa
75
76
export interface MatAutocompleteDefaultOptions {
76
77
/** Whether the first option should be highlighted when an autocomplete panel is opened. */
77
78
autoActiveFirstOption ?: boolean ;
79
+
80
+ /** Extra CSS classes to be added to the autocomplete panel. */
81
+ panelClass ?: string | string [ ] ;
78
82
}
79
83
80
84
/** Injection token to be used to override the default options for `mat-autocomplete`. */
@@ -167,16 +171,13 @@ export abstract class _MatAutocompleteBase extends _MatAutocompleteMixinBase imp
167
171
*/
168
172
@Input ( 'class' )
169
173
set classList ( value : string ) {
174
+ this . _resetClassList ( ) ;
175
+ this . _setVisibilityClasses ( this . _classList ) ;
176
+
170
177
if ( value && value . length ) {
171
- this . _classList = value . split ( ' ' ) . reduce ( ( classList , className ) => {
172
- classList [ className . trim ( ) ] = true ;
173
- return classList ;
174
- } , { } as { [ key : string ] : boolean } ) ;
175
- } else {
176
- this . _classList = { } ;
178
+ this . _classList [ value ] = true ;
177
179
}
178
180
179
- this . _setVisibilityClasses ( this . _classList ) ;
180
181
this . _elementRef . nativeElement . className = '' ;
181
182
}
182
183
_classList : { [ key : string ] : boolean } = { } ;
@@ -187,10 +188,11 @@ export abstract class _MatAutocompleteBase extends _MatAutocompleteMixinBase imp
187
188
constructor (
188
189
private _changeDetectorRef : ChangeDetectorRef ,
189
190
private _elementRef : ElementRef < HTMLElement > ,
190
- @Inject ( MAT_AUTOCOMPLETE_DEFAULT_OPTIONS ) defaults : MatAutocompleteDefaultOptions ) {
191
+ @Inject ( MAT_AUTOCOMPLETE_DEFAULT_OPTIONS ) private _defaults : MatAutocompleteDefaultOptions ) {
191
192
super ( ) ;
192
193
193
- this . _autoActiveFirstOption = ! ! defaults . autoActiveFirstOption ;
194
+ this . _autoActiveFirstOption = ! ! _defaults . autoActiveFirstOption ;
195
+ this . _resetClassList ( ) ;
194
196
}
195
197
196
198
ngAfterContentInit ( ) {
@@ -207,6 +209,15 @@ export abstract class _MatAutocompleteBase extends _MatAutocompleteMixinBase imp
207
209
this . _activeOptionChanges . unsubscribe ( ) ;
208
210
}
209
211
212
+ /** Sets the default value for the classes applied to the panel. */
213
+ _resetClassList ( ) {
214
+ this . _classList = { } ;
215
+
216
+ if ( this . _defaults . panelClass ) {
217
+ this . _classList [ coerceArray ( this . _defaults . panelClass ) . join ( ' ' ) ] = true ;
218
+ }
219
+ }
220
+
210
221
/**
211
222
* Sets the panel scrollTop. This allows us to manually scroll to display options
212
223
* above or below the fold, as they are not actually being focused when active.
0 commit comments