Skip to content

Commit

Permalink
fix(snackbar): always keep permanent snackbar
Browse files Browse the repository at this point in the history
  • Loading branch information
alimd committed Feb 3, 2023
1 parent d256f29 commit 1932239
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion ui/ui-kit/src/snackbar/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ const paintDelay = 60;
let closeLastSnackbar: ((response: SnackbarResponse) => void) | null = null;

commandHandler.define<SnackbarOptions, SnackbarResponse>('show-snackbar-command', (options) => {
if (options.duration === -1 && !options.actionLabel) delete options.duration;
logger.logMethodArgs('showSnackbar', options);
return new Promise((resolve) => {
const element = document.body.appendChild(document.createElement('alwatr-snackbar'));

let closed = false;
const _closeSnackbar = (response: SnackbarResponse): void => {
if (closed) return;
if (!response.actionButton && options.duration === -1) return; // keep it!
logger.logMethodArgs('closeSnackbar', response);
closed = true;
closeLastSnackbar = null;
Expand All @@ -37,7 +39,7 @@ commandHandler.define<SnackbarOptions, SnackbarResponse>('show-snackbar-command'
element.open = true;
closeLastSnackbar?.({});
closeLastSnackbar = _closeSnackbar;
if (!(options.duration === -1 && element.actionLabel)) {
if (options.duration !== -1) {
setTimeout(() => _closeSnackbar?.({}), clamp(options.duration ?? 5_000, 4_000, 10_000));
}
}, paintDelay);
Expand Down

0 comments on commit 1932239

Please sign in to comment.