File tree Expand file tree Collapse file tree 3 files changed +23
-7
lines changed Expand file tree Collapse file tree 3 files changed +23
-7
lines changed Original file line number Diff line number Diff line change @@ -261,4 +261,18 @@ describe('Integration Tests', () => {
261
261
. get ( '._toastBtn' )
262
262
. click ( )
263
263
} )
264
+
265
+ it ( 'Runs callback when toast is popped programatically' , ( ) => {
266
+ cy . get ( '[data-btn=runCallbackOnToastRemoval]' )
267
+ . click ( )
268
+ . get ( '._toastItem' )
269
+ . contains ( 'Wait for it' )
270
+ . window ( )
271
+ . invoke ( 'toast.pop' )
272
+ . wait ( 500 )
273
+ . get ( '._toastItem' )
274
+ . contains ( 'callback has been executed' )
275
+ . get ( '._toastBtn' )
276
+ . click ( )
277
+ } )
264
278
} )
Original file line number Diff line number Diff line change @@ -269,6 +269,7 @@ toast.pop(0)`,
269
269
target: ' new' ,
270
270
dismissable: false ,
271
271
initial: 0 ,
272
+ intro: { y: - 192 },
272
273
theme: {
273
274
' --toastPadding' : ' 0' ,
274
275
' --toastMsgPadding' : ' 0' ,
Original file line number Diff line number Diff line change 1
1
<script >
2
+ import { onDestroy } from ' svelte'
2
3
import { tweened } from ' svelte/motion'
3
4
import { linear } from ' svelte/easing'
4
5
import { toast } from ' ./stores.js'
5
6
6
7
export let item
7
8
8
9
const progress = tweened (item .initial , { duration: item .duration , easing: linear })
9
- const close = () => {
10
- const { id , onpop } = item
11
- toast .pop (id)
12
- if (typeof onpop === ' function' ) {
13
- onpop (id)
14
- }
15
- }
10
+ const close = () => toast .pop (item .id )
16
11
const autoclose = () => {
17
12
if ($progress === 1 || $progress === 0 ) {
18
13
close ()
@@ -57,6 +52,12 @@ const getProps = () => {
57
52
$: if (typeof item .progress !== ' undefined' ) {
58
53
item .next = item .progress
59
54
}
55
+
56
+ onDestroy (() => {
57
+ if (typeof item .onpop === ' function' ) {
58
+ item .onpop (item .id )
59
+ }
60
+ })
60
61
</script >
61
62
62
63
<style >
You can’t perform that action at this time.
0 commit comments