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(snack-bar): indicate in afterDismissed whether dismissal was a result of an action #9154

Merged

Conversation

crisbeto
Copy link
Member

Adds a boolean to the MatSnackBarRef.afterDismissed result that indicates whether the dismissal came as a result of the user pressing the action button.

Fixes #9147.

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Dec 28, 2017
@@ -84,13 +88,18 @@ export class MatSnackBarRef<T> {
this._onAction.complete();
}

this._afterClosed.next();
this._afterClosed.complete();
this._afterDismissed.next(this._dismissedWithAction);
Copy link
Member Author

Choose a reason for hiding this comment

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

@josephperrott I'm also open to having a reason parameter on the dismiss method. I didn't go with it now, because it would mean that we'd need some magical string (e.g. 'action'), because the consumer doesn't usually have access to the action button on the SimpleSnackBar.

* The stream emits a boolean that indicates whether the snack bar was dismissed
* using the action button.
*/
afterDismissed(): Observable<boolean> {
Copy link
Member

Choose a reason for hiding this comment

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

Instead of making this a boolean stream, I'd rather add an event object so that we could add more information to it in the future.

@crisbeto crisbeto force-pushed the 9147/snack-bar-ref-after-dismissed branch from 40ac2ce to 1522681 Compare January 13, 2018 11:22
@crisbeto
Copy link
Member Author

Addressed the feedback @jelbourn.

@@ -11,6 +11,12 @@ import {Observable} from 'rxjs/Observable';
import {Subject} from 'rxjs/Subject';
import {MatSnackBarContainer} from './snack-bar-container';

/** Event that is emitted when a snack bar is dismissed. */
export interface MatSnackBarAfterDismiss {
Copy link
Member

Choose a reason for hiding this comment

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

How about just MatSnackBarDismiss or MatSnackBarDismissal? The "after" in the stream name makes sense because it relates to when the event is emitted, but there's nothing about the event object that's specific to it being at that time

Copy link
Member Author

Choose a reason for hiding this comment

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

Renamed to MatSnackBarDismiss.

@crisbeto crisbeto force-pushed the 9147/snack-bar-ref-after-dismissed branch from 1522681 to 045aefb Compare January 17, 2018 17:42
/** Event that is emitted when a snack bar is dismissed. */
export interface MatSnackBarDismiss {
/** Whether the snack bar was dismissied using the action button. */
dismissedByAction: boolean;
Copy link
Member

Choose a reason for hiding this comment

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

Should this be closedByAction since the method that would cause this to be true is closeWithAction()?

Copy link
Member Author

@crisbeto crisbeto Jan 18, 2018

Choose a reason for hiding this comment

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

That's true, but the method that returns it is called afterDismissed. Either way it would be slightly confusing.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should mark one of the terms as deprecated to fix it long term? I am good with either wording being removed, just as long as we create consistency.

Copy link
Member Author

Choose a reason for hiding this comment

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

My vote is for removing the "dismissed" wording and calling it "close" (also renaming the dismiss method). That way it's consistent with the dialog as well.

Copy link
Member

Choose a reason for hiding this comment

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

SGTM

@crisbeto crisbeto force-pushed the 9147/snack-bar-ref-after-dismissed branch from 045aefb to 846ba98 Compare January 18, 2018 18:54
@crisbeto
Copy link
Member Author

Done @josephperrott.

@jelbourn
Copy link
Member

jelbourn commented Jan 18, 2018

My opinion: dismiss is more appropriate for snackbar because you would, in conversation, use "dismiss" when the subject noun is "notification". I think the inconsistency is English language inconsistency leaking through (e.g. you get in a car but on a bus). I don't feel super strongly about it, but would lean on the side of not changing the API without a compelling technical reason.

…sult of an action

Adds a boolean to the `MatSnackBarRef.afterDismissed` result that indicates whether the dismissal came as a result of the user pressing the action button.

Fixes angular#9147.
@crisbeto crisbeto force-pushed the 9147/snack-bar-ref-after-dismissed branch from 846ba98 to e378824 Compare January 19, 2018 20:49
@crisbeto
Copy link
Member Author

Switched back to the dismiss terminology and deprecated closeWithAction. Can you take another look @josephperrott?

Copy link
Member

@josephperrott josephperrott left a comment

Choose a reason for hiding this comment

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

LGTM

@josephperrott josephperrott added pr: lgtm action: merge The PR is ready for merge by the caretaker target: minor This PR is targeted for the next minor release and removed pr: needs review labels Jan 19, 2018
@jelbourn jelbourn merged commit 829506d into angular:master Jan 23, 2018
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement target: minor This PR is targeted for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Know if a snackbar is dismissed by action or not
4 participants