Skip to content

Commit 064170b

Browse files
authored
Fix visible toast messages flickering when one disappears (#4749)
1 parent 393f889 commit 064170b

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

src/renderer/components/ft-toast/ft-toast.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { defineComponent } from 'vue'
22
import FtToastEvents from './ft-toast-events.js'
33

4+
let id = 0
5+
46
export default defineComponent({
57
name: 'FtToast',
68
data: function () {
@@ -15,7 +17,9 @@ export default defineComponent({
1517
FtToastEvents.removeEventListener('toast-open', this.open)
1618
},
1719
methods: {
18-
performAction: function (index) {
20+
performAction: function (id) {
21+
const index = this.toasts.findIndex(toast => id === toast.id)
22+
1923
this.toasts[index].action()
2024
this.remove(index)
2125
},
@@ -26,7 +30,13 @@ export default defineComponent({
2630
toast.isOpen = false
2731
},
2832
open: function ({ detail: { message, time, action } }) {
29-
const toast = { message: message, action: action || (() => { }), isOpen: false, timeout: null }
33+
const toast = {
34+
message: message,
35+
action: action || (() => { }),
36+
isOpen: false,
37+
timeout: null,
38+
id: id++
39+
}
3040
toast.timeout = setTimeout(this.close, time || 3000, toast)
3141
setTimeout(() => { toast.isOpen = true })
3242
if (this.toasts.length > 4) {

src/renderer/components/ft-toast/ft-toast.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<template>
22
<div class="toast-holder">
33
<div
4-
v-for="(toast, index) in toasts"
5-
:key="'toast-' + index"
4+
v-for="toast in toasts"
5+
:key="toast.id"
66
class="toast"
77
:class="{ closed: !toast.isOpen, open: toast.isOpen }"
88
tabindex="0"
99
role="status"
10-
@click="performAction(index)"
11-
@keydown.enter.prevent="performAction(index)"
12-
@keydown.space.prevent="performAction(index)"
10+
@click="performAction(toast.id)"
11+
@keydown.enter.prevent="performAction(toast.id)"
12+
@keydown.space.prevent="performAction(toast.id)"
1313
>
1414
<p class="message">
1515
{{ toast.message }}

0 commit comments

Comments
 (0)