Skip to content

Commit

Permalink
docs(snackbar): review and enhancement
Browse files Browse the repository at this point in the history
  • Loading branch information
njfamirm committed Jan 4, 2025
1 parent 5084f9c commit c0a4a89
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
1 change: 1 addition & 0 deletions packages/snackbar/src/lib/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export class SnackbarElement extends LightDomMixin(LoggerMixin(LitElement)) {
* Waits for the closing animation to end before removing the element.
*
* @internal
* This method should be used by the package API, not directly, to ensure proper signal unsubscription.
*/
async close(): Promise<void> {
this.logger_.logMethod?.('close');
Expand Down
11 changes: 6 additions & 5 deletions packages/snackbar/src/lib/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,19 @@ function createSnackbarElement(options: SnackbarOptions): SnackbarElement {
function handleActionButtonClick(closeSnackbar: () => Promise<void>, handler?: SnackbarActionHandler): void {
logger.logMethod?.('handleActionButtonClick');

const actionButtonClickHandler = async () => {
const actionButtonClickHandler = () => {
logger.logOther?.('Snackbar action button clicked.');

await handler?.();
handler?.();
return closeSnackbar();
};

/**
* Store the function to unsubscribe the action button handler after close or action button clicked.
*
* TODO: check why once not work
*/
unsubscribeActionButtonHandler = snackbarActionButtonClickedSignal.subscribe(actionButtonClickHandler.bind(null), {
// once: true, // not work!
}).unsubscribe;
unsubscribeActionButtonHandler = snackbarActionButtonClickedSignal.subscribe(actionButtonClickHandler.bind(null)).unsubscribe;
}

/**
Expand Down Expand Up @@ -99,6 +99,7 @@ async function showSnackbar(options: SnackbarOptions): Promise<void> {
}

if (options.addCloseButton === true) {
// TODO: check why once not work
unsubscribeCloseButtonHandler = snackbarCloseButtonClickedSignal.subscribe(closeSnackbar.bind(null)).unsubscribe;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/snackbar/src/lib/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export type SnackbarOptions = {
*/
action?: {
/**
* The signal ID to be emitted when the action button is clicked.
* The handler to be called when the action button is clicked.
*/
handler: SnackbarActionHandler;

Expand Down

0 comments on commit c0a4a89

Please sign in to comment.