Skip to content

Commit

Permalink
feat(snack-bar): add dismiss method to MdSnackBar service (#3069)
Browse files Browse the repository at this point in the history
Adds a `dismiss` method to the snack bar service, which dismisses the currently-open instance, mostly for convenience since the spec only allows one snack bar to open at a time.
  • Loading branch information
crisbeto authored and mmalerba committed Feb 21, 2017
1 parent bd6feb3 commit 83b5842
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/lib/snack-bar/snack-bar.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,19 @@ describe('MdSnackBar', () => {
});
}));

it('should be able to get dismissed through the service', async(() => {
snackBar.open(simpleMessage);
viewContainerFixture.detectChanges();
expect(overlayContainerElement.childElementCount).toBeGreaterThan(0);

snackBar.dismiss();
viewContainerFixture.detectChanges();

viewContainerFixture.whenStable().then(() => {
expect(overlayContainerElement.childElementCount).toBe(0);
});
}));

it('should clean itself up when the view container gets destroyed', async(() => {
snackBar.open(simpleMessage, null, { viewContainerRef: testViewContainerRef });
viewContainerFixture.detectChanges();
Expand Down
9 changes: 9 additions & 0 deletions src/lib/snack-bar/snack-bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,15 @@ export class MdSnackBar {
return simpleSnackBarRef;
}

/**
* Dismisses the currently-visible snack bar.
*/

This comment has been minimized.

Copy link
@VitalyVrublevskyy

VitalyVrublevskyy May 12, 2017

@crisbeto Does we have any option to autohide snankbar on page change (router change)?

This comment has been minimized.

Copy link
@crisbeto

crisbeto May 12, 2017

Author Member

Not at the moment, but it makes sense to add it. I've included it in my backlog.

This comment has been minimized.

Copy link
@VitalyVrublevskyy

VitalyVrublevskyy May 12, 2017

@crisbeto It would be great!

dismiss(): void {
if (this._openedSnackBarRef) {
this._openedSnackBarRef.dismiss();
}
}

/**
* Attaches the snack bar container component to the overlay.
*/
Expand Down

0 comments on commit 83b5842

Please sign in to comment.