@@ -15,6 +15,8 @@ import {SimpleSnackBar} from './simple-snack-bar';
1515import  { MAT_SNACK_BAR_DATA ,  MatSnackBarConfig }  from  './snack-bar-config' ; 
1616import  { MatSnackBarContainer }  from  './snack-bar-container' ; 
1717import  { MatSnackBarRef }  from  './snack-bar-ref' ; 
18+ import  { Observable }  from  'rxjs/Observable' ; 
19+ import  { BreakpointObserver ,  Breakpoints ,  BreakpointState }  from  '@angular/cdk/layout' ; 
1820
1921
2022/** 
@@ -47,6 +49,7 @@ export class MatSnackBar {
4749      private  _overlay : Overlay , 
4850      private  _live : LiveAnnouncer , 
4951      private  _injector : Injector , 
52+       private  _breakpointObserver : BreakpointObserver , 
5053      @Optional ( )  @SkipSelf ( )  private  _parentSnackBar : MatSnackBar )  { } 
5154
5255  /** 
@@ -145,6 +148,18 @@ export class MatSnackBar {
145148    // We can't pass this via the injector, because the injector is created earlier. 
146149    snackBarRef . instance  =  contentRef . instance ; 
147150
151+     // Subscribe to the breakpoint observer and attacg the mat-snack-bar-handset class as 
152+     // appropriate. This class is applied to the overlay element because the overlay must expand to 
153+     // fill the width of the screen for full width snackbars. 
154+     const  isHandset  =  this . _breakpointObserver . observe ( Breakpoints . Handset ) . subscribe ( state  =>  { 
155+       overlayRef . overlayElement . classList . toggle ( 'mat-snack-bar-handset' ,  state . matches ) ; 
156+     } ) ; 
157+     // Unsubscribe from the isHandset subscription when the overlay is detached from the view. 
158+     const  overlayDetach  =  overlayRef . detachments ( ) . subscribe ( ( )  =>  { 
159+       overlayDetach . unsubscribe ( ) ; 
160+       isHandset . unsubscribe ( ) ; 
161+     } ) ; 
162+ 
148163    return  snackBarRef ; 
149164  } 
150165
0 commit comments