-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
feat(snackbar): add timeout for snackbar #1856
Conversation
990a333
to
5d1abd9
Compare
@@ -13,4 +13,7 @@ export class MdSnackBarConfig { | |||
|
|||
/** The view container to place the overlay for the snack bar into. */ | |||
viewContainerRef?: ViewContainerRef = null; | |||
|
|||
/** The length of time in milliseconds to wait before automatically dismissing the snack bar. */ | |||
autoHide?: number = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's just call this duration
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -64,6 +62,10 @@ export class MdSnackBar { | |||
} else { | |||
snackBarRef.containerInstance.enter(); | |||
} | |||
if (config.autoHide > 0) { | |||
setTimeout(() => snackBarRef.dismiss(), config.autoHide + 225); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the 225
baked in here? (I'm assuming it's the animation duration, but doesn't dismiss handle that already?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgot I had this in there.
Yes, the 225 is for the animation. Created a todo to handle the case I was looking at.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
|
||
tick(1000); | ||
viewContainerFixture.detectChanges(); | ||
viewContainerFixture.whenStable().then(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You shouldn't need to use whenStable
with fakeAsync
because the whenStable
will just be called synchronously.
(same for other uses)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was unable to get my tests working without whenStable, so I will have to dig in more there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now it works, not sure what happened before.
@@ -64,6 +62,10 @@ export class MdSnackBar { | |||
} else { | |||
snackBarRef.containerInstance.enter(); | |||
} | |||
if (config.autoHide > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should do config.duration && cofig.duration > 0
in case someone sets it to null or undefined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use strict null checking?
We can then use the Non-null assertion operator
for instance in this case it would be:
if (config.autoHide! > 0) {
98120fa
to
296f38b
Compare
a976d62
to
89f9b55
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ugh, I left this comment a day ago and never sent it.
@@ -13,4 +13,7 @@ export class MdSnackBarConfig { | |||
|
|||
/** The view container to place the overlay for the snack bar into. */ | |||
viewContainerRef?: ViewContainerRef = null; | |||
|
|||
/** The length of time in milliseconds to wait before automatically dismissing the snack bar. */ | |||
dismiss?: number = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
duration
?
(I think you may have brained one thing and keyboarded another)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
89f9b55
to
bf6d542
Compare
@@ -15,6 +15,7 @@ | |||
| `viewContainerRef: ViewContainerRef` | The view container ref to attach the snack bar to. | | |||
| `role: AriaLivePoliteness = 'assertive'` | The politeness level to announce the snack bar with. | | |||
| `announcementMessage: string` | The message to announce with the snack bar. | | |||
| `dismiss: number` | The length of time in milliseconds to wait before autodismissing the snack bar. | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missed dismiss
> duration
here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
bf6d542
to
52aa060
Compare
LGTM |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
No description provided.