Skip to content

Commit

Permalink
feat(MdSnackbar): keep alive if its persistent (#1561)
Browse files Browse the repository at this point in the history
* fix(MdSnackbar): keep alive if its persistent

* docs(MdSnackbar): add `md-persistent` prop
  • Loading branch information
Samuell1 authored and marcosmoura committed Mar 1, 2018
1 parent 6f48688 commit 33007b4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
6 changes: 6 additions & 0 deletions docs/app/pages/Components/Snackbar/Snackbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@
description: 'Sets the duration in milliseconds before close the snackbar.',
defaults: '4000'
},
{
name: 'md-persistent',
type: 'Boolean',
description: 'This will make the snackbar persistent in your application, even changing routes.',
defaults: 'false'
},
{
name: 'md-position',
type: 'String',
Expand Down
2 changes: 1 addition & 1 deletion src/components/MdSnackbar/MdSnackbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
watch: {
mdActive (isActive) {
if (isActive) {
createSnackbar(this.mdDuration, this).then(() => {
createSnackbar(this.mdDuration, this.mdPersistent, this).then(() => {
this.$emit('update:mdActive', false)
this.$emit('md-opened')
})
Expand Down
6 changes: 4 additions & 2 deletions src/components/MdSnackbar/MdSnackbarQueue.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
let currentSnackbar = null
let timeout = null

function createPromise (duration, context) {
function createPromise (duration, persistent, context) {
return new Promise(resolve => {
currentSnackbar = {
destroy: () => {
Expand All @@ -13,7 +13,9 @@ function createPromise (duration, context) {
if (duration !== Infinity) {
timeout = window.setTimeout(() => {
destroySnackbar()
context._vnode.componentInstance.initDestroy(true)
if (!persistent) {
context._vnode.componentInstance.initDestroy(true)
}
}, duration)
}
})
Expand Down

0 comments on commit 33007b4

Please sign in to comment.