@@ -30,6 +30,14 @@ import {take} from 'rxjs/operators';
30
30
import { matSnackBarAnimations } from './snack-bar-animations' ;
31
31
import { MatSnackBarConfig } from './snack-bar-config' ;
32
32
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 ( ) ;
33
41
34
42
/**
35
43
* Internal component that wraps user-provided snack bar content.
@@ -113,14 +121,14 @@ export class MatSnackBarContainer extends BasePortalOutlet implements OnDestroy
113
121
/** Begin animation of snack bar entrance into view. */
114
122
enter ( ) : void {
115
123
if ( ! this . _destroyed ) {
116
- this . _animationState = `visible-${ this . snackBarConfig . verticalPosition } ` ;
124
+ this . _animationState = `visible-${ this . _getVerticalPosition ( ) } ` ;
117
125
this . _changeDetectorRef . detectChanges ( ) ;
118
126
}
119
127
}
120
128
121
129
/** Begin animation of the snack bar exiting from view. */
122
130
exit ( ) : Observable < void > {
123
- this . _animationState = `hidden-${ this . snackBarConfig . verticalPosition } ` ;
131
+ this . _animationState = `hidden-${ this . _getVerticalPosition ( ) } ` ;
124
132
return this . _onExit ;
125
133
}
126
134
@@ -155,11 +163,11 @@ export class MatSnackBarContainer extends BasePortalOutlet implements OnDestroy
155
163
}
156
164
}
157
165
158
- if ( this . snackBarConfig . horizontalPosition === 'center' ) {
166
+ if ( ( this . snackBarConfig . horizontalPosition || defaultHorizontalPosition ) === 'center' ) {
159
167
element . classList . add ( 'mat-snack-bar-center' ) ;
160
168
}
161
169
162
- if ( this . snackBarConfig . verticalPosition === 'top' ) {
170
+ if ( this . _getVerticalPosition ( ) === 'top' ) {
163
171
element . classList . add ( 'mat-snack-bar-top' ) ;
164
172
}
165
173
}
@@ -170,4 +178,8 @@ export class MatSnackBarContainer extends BasePortalOutlet implements OnDestroy
170
178
throw Error ( 'Attempting to attach snack bar content after content is already attached' ) ;
171
179
}
172
180
}
181
+
182
+ private _getVerticalPosition ( ) {
183
+ return this . snackBarConfig . verticalPosition || defaultVerticalPosition ;
184
+ }
173
185
}
0 commit comments