@@ -30,6 +30,14 @@ import {take} from 'rxjs/operators';
3030import { matSnackBarAnimations } from './snack-bar-animations' ;
3131import { MatSnackBarConfig } from './snack-bar-config' ;
3232
33+ /**
34+ * Default positions to be used as fallbacks if necessary.
35+ * @docs -private
36+ */
37+ const {
38+ horizontalPosition : defaultHorizontalPosition ,
39+ verticalPosition : defaultVerticalPosition
40+ } = new MatSnackBarConfig ( ) ;
3341
3442/**
3543 * Internal component that wraps user-provided snack bar content.
@@ -113,14 +121,14 @@ export class MatSnackBarContainer extends BasePortalOutlet implements OnDestroy
113121 /** Begin animation of snack bar entrance into view. */
114122 enter ( ) : void {
115123 if ( ! this . _destroyed ) {
116- this . _animationState = `visible-${ this . snackBarConfig . verticalPosition } ` ;
124+ this . _animationState = `visible-${ this . _getVerticalPosition ( ) } ` ;
117125 this . _changeDetectorRef . detectChanges ( ) ;
118126 }
119127 }
120128
121129 /** Begin animation of the snack bar exiting from view. */
122130 exit ( ) : Observable < void > {
123- this . _animationState = `hidden-${ this . snackBarConfig . verticalPosition } ` ;
131+ this . _animationState = `hidden-${ this . _getVerticalPosition ( ) } ` ;
124132 return this . _onExit ;
125133 }
126134
@@ -155,11 +163,11 @@ export class MatSnackBarContainer extends BasePortalOutlet implements OnDestroy
155163 }
156164 }
157165
158- if ( this . snackBarConfig . horizontalPosition === 'center' ) {
166+ if ( ( this . snackBarConfig . horizontalPosition || defaultHorizontalPosition ) === 'center' ) {
159167 element . classList . add ( 'mat-snack-bar-center' ) ;
160168 }
161169
162- if ( this . snackBarConfig . verticalPosition === 'top' ) {
170+ if ( this . _getVerticalPosition ( ) === 'top' ) {
163171 element . classList . add ( 'mat-snack-bar-top' ) ;
164172 }
165173 }
@@ -170,4 +178,8 @@ export class MatSnackBarContainer extends BasePortalOutlet implements OnDestroy
170178 throw Error ( 'Attempting to attach snack bar content after content is already attached' ) ;
171179 }
172180 }
181+
182+ private _getVerticalPosition ( ) {
183+ return this . snackBarConfig . verticalPosition || defaultVerticalPosition ;
184+ }
173185}
0 commit comments