carbon-design-system / carbon-components-svelte

Svelte implementation of the Carbon Design System
https://svelte.carbondesignsystem.com
Apache License 2.0
2.71k stars 261 forks source link

`ToastNotification` close event can fire after close due to timeout #1914

Closed brunnerh closed 8 months ago

brunnerh commented 9 months ago

ToastNotification has a built-in timeout mechanism, which automatically closes the toast and fires the close event.

However, if the toast is dismissed manually in that timeframe, the timeout is not stopped and there will be two close events. First the one from the click, then the one from the timeout.

Example:

const t = new ToastNotification({
    target: document.body,
    props: { timeout: 2000, title: 'Close this before timeout' },
});
t.$on('close', e => { console.log(e.detail); });

REPL

The timeout should probably be cleared as soon as the toast is closed. Also, it analogously should be started on open, not just onMount.

metonym commented 8 months ago

Fixed in v0.82.11.

Example in docs.