-
Notifications
You must be signed in to change notification settings - Fork 6.8k
feat(snackbar): Auto Hide for Snackbar #1641
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,16 @@ export class MdSnackBarConfig { | |
/** The view container to place the overlay for the snack bar into. */ | ||
viewContainerRef: ViewContainerRef; | ||
|
||
constructor(viewContainerRef: ViewContainerRef) { | ||
/* | ||
* The number of milliseconds to wait before automatically dismissing. | ||
* If no value is specified the snackbar will dismiss normally. | ||
* If a value is provided the snackbar can still be dismissed normally. | ||
* If a snackbar is dismissed before the timer expires, the timer will be cleared. | ||
*/ | ||
autoHideDuration: number | boolean; | ||
|
||
constructor(viewContainerRef: ViewContainerRef, autoHideDuration: number | boolean = false) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rather than being a constructor argument, this should just be a property that is set to the config with a default. We will shortly be giving the snackbar config the same treatment as the dialog config (#1679). |
||
this.viewContainerRef = viewContainerRef; | ||
this.autoHideDuration = autoHideDuration; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,8 @@ export class MdSnackBarRef<T> { | |
/** Subject for notifying the user that the snack bar has closed. */ | ||
private _afterClosed: Subject<any> = new Subject(); | ||
|
||
autoHide: number; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
constructor(instance: T, | ||
containerInstance: MdSnackBarContainer, | ||
private _overlayRef: OverlayRef) { | ||
|
@@ -36,6 +38,10 @@ export class MdSnackBarRef<T> { | |
this._afterClosed.complete(); | ||
}); | ||
} | ||
// Clear autohide interval | ||
if (this.autoHide) { | ||
clearInterval(this.autoHide); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you use |
||
} | ||
} | ||
|
||
/** Gets an observable that is notified when the snack bar is finished closing. */ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,8 +21,6 @@ import {MdSnackBarRef} from './snack-bar-ref'; | |
import {MdSnackBarContainer} from './snack-bar-container'; | ||
import {SimpleSnackBar} from './simple-snack-bar'; | ||
|
||
// TODO(josephperrott): Automate dismiss after timeout. | ||
|
||
|
||
/** | ||
* Service to dispatch Material Design snack bar messages. | ||
|
@@ -56,6 +54,12 @@ export class MdSnackBar { | |
} else { | ||
mdSnackBarRef.containerInstance.enter(); | ||
} | ||
// Auto dismiss after timeout. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment like // If the snackbar has a specified duration, set up a timeout to automatically dismiss it. |
||
if (config.autoHideDuration) { | ||
mdSnackBarRef.autoHide = setTimeout(() => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't need the braces: mdSnackBarRef._autoDismissTimeoutId =
setTimeout(() => mdSnackBarRef.dismiss(), config.duration); |
||
mdSnackBarRef.dismiss(); | ||
}, config.autoHideDuration); | ||
} | ||
this._live.announce(config.announcementMessage, config.politeness); | ||
this._snackBarRef = mdSnackBarRef; | ||
return this._snackBarRef; | ||
|
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 would just call this
duration
, where the value isnull
if it is persistent.