Skip to content

Commit 33007b4

Browse files
Samuell1marcosmoura
authored andcommitted
feat(MdSnackbar): keep alive if its persistent (vuematerial#1561)
* fix(MdSnackbar): keep alive if its persistent * docs(MdSnackbar): add `md-persistent` prop
1 parent 6f48688 commit 33007b4

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

docs/app/pages/Components/Snackbar/Snackbar.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@
4545
description: 'Sets the duration in milliseconds before close the snackbar.',
4646
defaults: '4000'
4747
},
48+
{
49+
name: 'md-persistent',
50+
type: 'Boolean',
51+
description: 'This will make the snackbar persistent in your application, even changing routes.',
52+
defaults: 'false'
53+
},
4854
{
4955
name: 'md-position',
5056
type: 'String',

src/components/MdSnackbar/MdSnackbar.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
watch: {
5151
mdActive (isActive) {
5252
if (isActive) {
53-
createSnackbar(this.mdDuration, this).then(() => {
53+
createSnackbar(this.mdDuration, this.mdPersistent, this).then(() => {
5454
this.$emit('update:mdActive', false)
5555
this.$emit('md-opened')
5656
})

src/components/MdSnackbar/MdSnackbarQueue.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
let currentSnackbar = null
22
let timeout = null
33

4-
function createPromise (duration, context) {
4+
function createPromise (duration, persistent, context) {
55
return new Promise(resolve => {
66
currentSnackbar = {
77
destroy: () => {
@@ -13,7 +13,9 @@ function createPromise (duration, context) {
1313
if (duration !== Infinity) {
1414
timeout = window.setTimeout(() => {
1515
destroySnackbar()
16-
context._vnode.componentInstance.initDestroy(true)
16+
if (!persistent) {
17+
context._vnode.componentInstance.initDestroy(true)
18+
}
1719
}, duration)
1820
}
1921
})

0 commit comments

Comments
 (0)