Skip to content

Commit 620896e

Browse files
authored
Implement onClose callback for Toast (#7969)
2 parents 8be1dd2 + 8e126f9 commit 620896e

File tree

4 files changed

+8
-1
lines changed

4 files changed

+8
-1
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
@@ -18,6 +18,7 @@ export type Toast = {
1818
*/
1919
alertVariant?: AlertVariant;
2020
variant?: AlertVariant;
21+
onClose?: () => void;
2122
};
2223

2324
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

packages/samples/react/vite.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,5 @@ export default defineConfig({
2929
},
3030
server: {
3131
port: 9191,
32-
strictPort: true,
3332
},
3433
});

0 commit comments

Comments
 (0)