Skip to content

Commit 8d12902

Browse files
crisbetojelbourn
authored andcommitted
fix(snack-bar): don't stretch to fullscreen in landscape orientation (#16940)
Currently the breakpoint that determines whether the snack bar should take up the full screen width also includes screens up to 960px in landscape orientation, which ends up looking weird for the short messages that usually got into tooltips. These changes switch the breakpoint to only be mobile devices in portrait mode. Fixes #16911.
1 parent 57998a2 commit 8d12902

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/material/snack-bar/snack-bar.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
TemplateRef,
2323
OnDestroy,
2424
} from '@angular/core';
25-
import {take, takeUntil} from 'rxjs/operators';
25+
import {takeUntil} from 'rxjs/operators';
2626
import {SimpleSnackBar} from './simple-snack-bar';
2727
import {MAT_SNACK_BAR_DATA, MatSnackBarConfig} from './snack-bar-config';
2828
import {MatSnackBarContainer} from './snack-bar-container';
@@ -185,14 +185,12 @@ export class MatSnackBar implements OnDestroy {
185185
// Subscribe to the breakpoint observer and attach the mat-snack-bar-handset class as
186186
// appropriate. This class is applied to the overlay element because the overlay must expand to
187187
// fill the width of the screen for full width snackbars.
188-
this._breakpointObserver.observe(Breakpoints.Handset).pipe(
189-
takeUntil(overlayRef.detachments().pipe(take(1)))
188+
this._breakpointObserver.observe(Breakpoints.HandsetPortrait).pipe(
189+
takeUntil(overlayRef.detachments())
190190
).subscribe(state => {
191-
if (state.matches) {
192-
overlayRef.overlayElement.classList.add('mat-snack-bar-handset');
193-
} else {
194-
overlayRef.overlayElement.classList.remove('mat-snack-bar-handset');
195-
}
191+
const classList = overlayRef.overlayElement.classList;
192+
const className = 'mat-snack-bar-handset';
193+
state.matches ? classList.add(className) : classList.remove(className);
196194
});
197195

198196
this._animateSnackBar(snackBarRef, config);

0 commit comments

Comments
 (0)