Skip to content

Commit acd3ac2

Browse files
committed
refactor(snackbar): set correct action button handler
1 parent de41512 commit acd3ac2

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

packages/snackbar/src/lib/handler.ts

+9-13
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,11 @@ function createSnackbarElement(options: SnackbarOptions): SnackbarElement {
5151
* @param closeSnackbar - Function to close the snackbar.
5252
* @param handler - Handler to be called when the action button is clicked.
5353
*/
54-
function handleActionButtonClick(closeSnackbar: () => Promise<void>, handler?: SnackbarActionHandler): void {
54+
function handleActionButtonClick(closeSnackbar: () => Promise<void>, handler?: SnackbarActionHandler): Promise<void> {
5555
logger.logMethod?.('handleActionButtonClick');
5656

57-
const actionButtonClickHandler = () => {
58-
logger.logOther?.('Snackbar action button clicked.');
59-
6057
handler?.();
6158
return closeSnackbar();
62-
};
63-
64-
/**
65-
* Store the function to unsubscribe the action button handler after close or action button clicked.
66-
*
67-
* TODO: check why once not work
68-
*/
69-
unsubscribeActionButtonHandler = snackbarActionButtonClickedSignal.subscribe(actionButtonClickHandler.bind(null)).unsubscribe;
7059
}
7160

7261
/**
@@ -95,7 +84,14 @@ async function showSnackbar(options: SnackbarOptions): Promise<void> {
9584
};
9685

9786
if (options.action != null) {
98-
handleActionButtonClick(closeSnackbar, options.action.handler);
87+
/**
88+
* Store the function to unsubscribe the action button handler after close or action button clicked.
89+
*
90+
* TODO: check why once not work
91+
*/
92+
unsubscribeActionButtonHandler = snackbarActionButtonClickedSignal.subscribe(
93+
handleActionButtonClick.bind(null, closeSnackbar, options.action.handler),
94+
).unsubscribe;
9995
}
10096

10197
if (options.addCloseButton === true) {

0 commit comments

Comments
 (0)