@@ -77,10 +77,23 @@ export class MatAutocomplete implements AfterContentInit {
7777 @Output ( ) optionSelected : EventEmitter < MatAutocompleteSelectedEvent > =
7878 new EventEmitter < MatAutocompleteSelectedEvent > ( ) ;
7979
80+ /**
81+ * Takes classes set on the host md-autocomplete element and applies them to the panel
82+ * inside the overlay container to allow for easy styling.
83+ */
84+ @Input ( 'class' )
85+ set classList ( classList : string ) {
86+ if ( classList && classList . length ) {
87+ classList . split ( ' ' ) . forEach ( className => this . _classList [ className . trim ( ) ] = true ) ;
88+ this . _elementRef . nativeElement . className = '' ;
89+ }
90+ }
91+ _classList : { [ key : string ] : boolean } = { } ;
92+
8093 /** Unique ID to be used by autocomplete trigger's "aria-owns" property. */
8194 id : string = `mat-autocomplete-${ _uniqueAutocompleteIdCounter ++ } ` ;
8295
83- constructor ( private _changeDetectorRef : ChangeDetectorRef ) { }
96+ constructor ( private _changeDetectorRef : ChangeDetectorRef , private _elementRef : ElementRef ) { }
8497
8598 ngAfterContentInit ( ) {
8699 this . _keyManager = new ActiveDescendantKeyManager < MatOption > ( this . options ) . withWrap ( ) ;
@@ -105,6 +118,8 @@ export class MatAutocomplete implements AfterContentInit {
105118 _setVisibility ( ) : void {
106119 Promise . resolve ( ) . then ( ( ) => {
107120 this . showPanel = ! ! this . options . length ;
121+ this . _classList [ 'mat-autocomplete-visible' ] = this . showPanel ;
122+ this . _classList [ 'mat-autocomplete-hidden' ] = ! this . showPanel ;
108123 this . _changeDetectorRef . markForCheck ( ) ;
109124 } ) ;
110125 }
@@ -114,14 +129,5 @@ export class MatAutocomplete implements AfterContentInit {
114129 const event = new MatAutocompleteSelectedEvent ( this , option ) ;
115130 this . optionSelected . emit ( event ) ;
116131 }
117-
118- /** Sets a class on the panel based on whether it is visible. */
119- _getClassList ( ) {
120- return {
121- 'mat-autocomplete-visible' : this . showPanel ,
122- 'mat-autocomplete-hidden' : ! this . showPanel
123- } ;
124- }
125-
126132}
127133
0 commit comments