Displayed toast (Snackbar) no longer updatable
Bug, feature request, or proposal:
Bug?
We use 'toast' as a notification to users of job progress ('Updating foo', 'Updated foo'). Jobs can last between 1 and 20 seconds. Some jobs spawn others which all generate notifications. As a method of reducing the amount of toast business (pop pop pop...), if a job finishes while its notification is still being displayed, we update the displayed toast to show the finished state (e.g. 'Updated foo').
Since updating to beta.11 this functionality seems not to work. Changing the message from within the snackbar component on a timer does not seem to work either.
Last seen to be working in beta.8
What is the expected behavior?
The ability to update the message shown by toast while it is being displayed
What is the current behavior?
Toast message remains static while being shown
What are the steps to reproduce?
Simplified example showing local (in the snackbar component) message update
https://plnkr.co/edit/szv0cW?p=preview
What is the use-case or motivation for changing an existing behavior?
Which versions of Angular, Material, OS, TypeScript, browsers are affected?
@angular/cli: 1.2.4 node: 7.2.0 os: win32 x64 @angular/animations: 4.4.3 @angular/cdk: 2.0.0-beta.11 @angular/common: 4.4.3 @angular/compiler: 4.4.3 @angular/core: 4.4.3 @angular/flex-layout: 2.0.0-beta.9 @angular/forms: 4.4.3 @angular/http: 4.4.3 @angular/material: 2.0.0-beta.11 @angular/platform-browser: 4.4.3 @angular/platform-browser-dynamic: 4.4.3 @angular/router: 4.4.3 @angular/cli: 1.2.4 @angular/compiler-cli: 4.4.3
Is there anything else we should know?
Material 2 is really nice to use, thanks for all your efforts :)
All the components have been switched to OnPush. Since the snackbar container is OnPush, change detection won't run for its child component (i.e. PizzaPartyComponent).
See https://plnkr.co/edit/UOEtZX?p=preview as an example of it working with markForCheck.
I wonder if there is a good way to illuminate this in the docs, since I think the snackbar is the only one affected in this manner.
Thanks @willshowell, your plunker has shown us a (the?) way.
Closing as the message not updating is working as expected.
To give more context/information:
- From the material spec:
For usability reasons, snackbars should not contain the only way to access a core use case. They should not be persistent or be stacked, as they are above other elements on screen.
As they should not be persistent, they should not stay on the screen for an indeterminate time such as the loading state you are referencing. Since they should not be on the screen as a single snackbar to represent the event, multiple snackbars should be used in lieu of updating text.
- Changing the text on the snackbar will not re-announce the change to screen readers making this a11y unfriendly.
While the way that @willshowell points will create the behavior you mention, it is not recommended for the reasons listed above.
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.