Skip to content

Commit b7486ac

Browse files
committed
Implement onClose callback for Toast
Refs: #7068
1 parent 79e12e8 commit b7486ac

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

packages/components/src/components/toaster/shadow.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export class KolToastContainer implements ToasterAPI {
7474
...this.state,
7575
_toastStates: this.state._toastStates.filter((localToastState) => localToastState.id !== toastState.id),
7676
};
77+
toastState.toast.onClose?.();
7778
}, TRANSITION_TIMEOUT);
7879
}
7980

@@ -101,6 +102,9 @@ export class KolToastContainer implements ToasterAPI {
101102
...this.state,
102103
_toastStates: this.state._toastStates.filter((toastState) => toastsToClose.every((toastToClose) => toastToClose.id !== toastState.id)),
103104
};
105+
toastsToClose.forEach((toastState) => {
106+
toastState.toast.onClose?.();
107+
});
104108
}, TRANSITION_TIMEOUT);
105109
}
106110
}

packages/components/src/schema/components/toaster.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export type Toast = {
1414
label: LabelPropType;
1515
type: AlertType;
1616
variant?: AlertVariant;
17+
onClose?: () => void;
1718
};
1819

1920
export type ToastState = {

packages/samples/react/src/components/toast/basic.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ export const ToastBasic: FC = () => {
2020
description: 'Toasty',
2121
label: `Initial Toast`,
2222
type: 'warning',
23+
onClose: () => {
24+
console.log('Simple toast has been closed.');
25+
},
2326
});
2427
};
2528

0 commit comments

Comments
 (0)