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', () => {
261261 . get ( '._toastBtn' )
262262 . click ( )
263263 } )
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+ } )
264278} )
Original file line number Diff line number Diff line change @@ -269,6 +269,7 @@ toast.pop(0)`,
269269 target: ' new' ,
270270 dismissable: false ,
271271 initial: 0 ,
272+ intro: { y: - 192 },
272273 theme: {
273274 ' --toastPadding' : ' 0' ,
274275 ' --toastMsgPadding' : ' 0' ,
Original file line number Diff line number Diff line change 11<script >
2+ import { onDestroy } from ' svelte'
23import { tweened } from ' svelte/motion'
34import { linear } from ' svelte/easing'
45import { toast } from ' ./stores.js'
56
67export let item
78
89const 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 )
1611const autoclose = () => {
1712 if ($progress === 1 || $progress === 0 ) {
1813 close ()
@@ -57,6 +52,12 @@ const getProps = () => {
5752$: if (typeof item .progress !== ' undefined' ) {
5853 item .next = item .progress
5954}
55+
56+ onDestroy (() => {
57+ if (typeof item .onpop === ' function' ) {
58+ item .onpop (item .id )
59+ }
60+ })
6061 </script >
6162
6263<style >
You can’t perform that action at this time.
0 commit comments