Skip to content

Commit f5377dd

Browse files
crisbetotinayuangao
authored andcommitted
fix(snack-bar): snack bar not animating in if no positions are passed in (#11230)
Adds some better handling for the case where no positions are passed into a snack bar. Currently the snack bar attempts to animate in to an invalid animation state. Fixes #11197.
1 parent 2d227b7 commit f5377dd

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/lib/snack-bar/snack-bar.spec.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,31 @@ describe('MatSnackBar', () => {
422422
.toContain('custom-class', 'Expected class applied through the defaults to be applied.');
423423
}));
424424

425+
it('should position the snack bar correctly if no default position is defined', fakeAsync(() => {
426+
overlayContainer.ngOnDestroy();
427+
viewContainerFixture.destroy();
428+
429+
TestBed
430+
.resetTestingModule()
431+
.overrideProvider(MAT_SNACK_BAR_DEFAULT_OPTIONS, {
432+
deps: [],
433+
useFactory: () => ({politeness: 'polite'})
434+
})
435+
.configureTestingModule({imports: [MatSnackBarModule, NoopAnimationsModule]})
436+
.compileComponents();
437+
438+
inject([MatSnackBar, OverlayContainer], (sb: MatSnackBar, oc: OverlayContainer) => {
439+
snackBar = sb;
440+
overlayContainer = oc;
441+
overlayContainerElement = oc.getContainerElement();
442+
})();
443+
444+
const snackBarRef = snackBar.open(simpleMessage);
445+
flush();
446+
447+
expect(snackBarRef.containerInstance._animationState).toBe('visible-bottom');
448+
}));
449+
425450
describe('with custom component', () => {
426451
it('should open a custom component', () => {
427452
const snackBarRef = snackBar.openFromComponent(BurritosNotification);

src/lib/snack-bar/snack-bar.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ export class MatSnackBar {
149149
private _attach<T>(content: ComponentType<T> | TemplateRef<T>, userConfig?: MatSnackBarConfig):
150150
MatSnackBarRef<T | EmbeddedViewRef<any>> {
151151

152-
const config = {...this._defaultConfig, ...userConfig};
152+
const config = {...new MatSnackBarConfig(), ...this._defaultConfig, ...userConfig};
153153
const overlayRef = this._createOverlay(config);
154154
const container = this._attachSnackBarContainer(overlayRef, config);
155155
const snackBarRef = new MatSnackBarRef<T | EmbeddedViewRef<any>>(container, overlayRef);

0 commit comments

Comments
 (0)