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

Know if a snackbar is dismissed by action or not #9147

Closed
patou opened this issue Dec 28, 2017 · 1 comment · Fixed by #9154
Closed

Know if a snackbar is dismissed by action or not #9147

patou opened this issue Dec 28, 2017 · 1 comment · Fixed by #9154
Assignees
Labels
P4 A relatively minor issue that is not relevant to core functions

Comments

@patou
Copy link

patou commented Dec 28, 2017

Proposal:

When the snackbar is dismissed by click on the action button, the observable onAction() is called, but also the observable afterDismissed().
When the snackbar is dismissed by the timer or the function dismiss(), there are just the afterDismissed() observable called.
There are no option to know if the dismissed has origin by the action or other.

The use case is to have a delete message with a cancel action, if the dismiss hasn't origin by the action, we must do the delete on server, otherwise restore in the interface the delete item.

What is the expected behavior?

We can add to boolean result in the afterDismissed :

    let snackBarRef = this.snackBar.open('The item has been removed', 'Cancel');
    snackBarRef.onAction().subscribe(() => {
      this.undoRemove();
    });
    snackBarRef.afterDismissed().subscribe((action) => {
      if (!action)
         this.doRemove();
    });

Or add a new observable :

    let snackBarRef = this.snackBar.open('The item has been removed', 'Cancel');
    snackBarRef.onAction().subscribe(() => {
      this.undoRemove();
    });
    snackBarRef.onDismiss().subscribe(() => {
       this.doRemove();
    });

What is the current behavior?

The observable afterDismissed is called everytime with or without action.

@crisbeto crisbeto self-assigned this Dec 28, 2017
@crisbeto crisbeto added the P4 A relatively minor issue that is not relevant to core functions label Dec 28, 2017
crisbeto added a commit to crisbeto/material2 that referenced this issue Dec 28, 2017
…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 added a commit to crisbeto/material2 that referenced this issue Jan 13, 2018
…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 added a commit to crisbeto/material2 that referenced this issue Jan 17, 2018
…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 added a commit to crisbeto/material2 that referenced this issue Jan 18, 2018
…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 added a commit to crisbeto/material2 that referenced this issue Jan 19, 2018
…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.
jelbourn pushed a commit that referenced this issue Jan 21, 2018
…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 #9147.
jelbourn pushed a commit that referenced this issue Jan 23, 2018
…sult of an action (#9154)

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.
@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
P4 A relatively minor issue that is not relevant to core functions
Projects
None yet
2 participants