Skip to content

Commit eb7f592

Browse files
committed
Toast: fix timeout update: fix #24
1 parent 3ee126a commit eb7f592

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/components/toast/Toast.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ export class Toast extends AbstractComponent<IToastAttrs> {
4545
this.startTimeout();
4646
} else if (prev.attrs.timeout! > 0 && vnode.attrs.timeout! <= 0) {
4747
this.clearTimeouts();
48+
} else if (vnode.attrs.timeout! !== prev.attrs.timeout) {
49+
this.clearTimeouts();
50+
this.startTimeout();
4851
}
4952
}
5053

src/components/toast/examples/declarative.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import m from 'mithril';
2-
import { Button, Toaster, Toast } from '@/';
2+
import { Button, Toaster, Toast, Switch } from '@/';
33
import { Example } from '@shared/examples';
44

55
const EXAMPLE_SRC = 'components/toast/examples/declarative.ts';
@@ -11,9 +11,10 @@ interface INotification {
1111

1212
export class ToastDeclarativeExample {
1313
private notifications: INotification[] = [];
14+
private timeout: number = 3000;
1415

1516
public view() {
16-
return m(Example, { src: EXAMPLE_SRC }, [
17+
return m(Example, { options: this.renderOptions(), src: EXAMPLE_SRC }, [
1718
m(Button, {
1819
label: 'Show toast',
1920
intent: 'primary',
@@ -24,7 +25,8 @@ export class ToastDeclarativeExample {
2425
toasts: this.notifications.map(notification => m(Toast, {
2526
key: notification.key,
2627
message: notification.message,
27-
onDismiss: this.dismiss
28+
onDismiss: this.dismiss,
29+
timeout: this.timeout
2830
}))
2931
})
3032
]);
@@ -41,4 +43,14 @@ export class ToastDeclarativeExample {
4143
const index = this.notifications.findIndex(x => x.key === key);
4244
this.notifications.splice(index, 1);
4345
}
46+
47+
private renderOptions() {
48+
return [
49+
m(Switch, {
50+
checked: this.timeout === 0,
51+
label: 'Timeout = 0',
52+
onchange: () => this.timeout = this.timeout === 0 ? 3000 : 0
53+
})
54+
];
55+
}
4456
}

0 commit comments

Comments
 (0)