Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(snackbar): make closeWithAction public method #5686

Merged
merged 2 commits into from
Jul 25, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib/snack-bar/simple-snack-bar.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
<button
class="mat-simple-snackbar-action"
*ngIf="hasAction"
(click)="dismiss()">{{data.action}}</button>
(click)="action()">{{data.action}}</button>
6 changes: 3 additions & 3 deletions src/lib/snack-bar/simple-snack-bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ export class SimpleSnackBar {
this.data = data;
}

/** Dismisses the snack bar. */
dismiss(): void {
this.snackBarRef._action();
/** Performs the action on the snack bar. */
action(): void {
this.snackBarRef.closeWithAction();
}

/** If the action button should be shown. */
Expand Down
18 changes: 9 additions & 9 deletions src/lib/snack-bar/snack-bar-ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ export class MdSnackBarRef<T> {
containerInstance: MdSnackBarContainer;

/** Subject for notifying the user that the snack bar has closed. */
private _afterClosed: Subject<any> = new Subject();
private _afterClosed = new Subject<void>();

/** Subject for notifying the user that the snack bar has opened and appeared. */
private _afterOpened: Subject<any>;
private _afterOpened = new Subject<void>();

/** Subject for notifying the user that the snack bar action was called. */
private _onAction: Subject<any> = new Subject();
private _onAction = new Subject<void>();

/**
* Timeout ID for the duration setTimeout call. Used to clear the timeout if the snackbar is
Expand All @@ -55,19 +55,19 @@ export class MdSnackBarRef<T> {
clearTimeout(this._durationTimeoutId);
}

/** Dismisses the snack bar after some duration */
_dismissAfter(duration: number): void {
this._durationTimeoutId = setTimeout(() => this.dismiss(), duration);
}

/** Marks the snackbar action clicked. */
_action(): void {
closeWithAction(): void {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is a public API now, could you add a unit test that is based around calling this? The current unit test only deals with clicking the button directly.

if (!this._onAction.closed) {
this._onAction.next();
this._onAction.complete();
}
}

/** Dismisses the snack bar after some duration */
_dismissAfter(duration: number): void {
this._durationTimeoutId = setTimeout(() => this.dismiss(), duration);
}

/** Marks the snackbar as opened */
_open(): void {
if (!this._afterOpened.closed) {
Expand Down