Skip to content

Commit

Permalink
Merge pull request #457 from danice/v2-dev
Browse files Browse the repository at this point in the history
Toast custom HTML with templates
  • Loading branch information
wuda-io committed May 21, 2024
2 parents bde6acc + 69c4cc6 commit 2a2dd9b
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/toasts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,13 @@ export class Toast {
}

_createToast() {
const toast = this.options.toastId
let toast: HTMLElement = this.options.toastId
? document.getElementById(this.options.toastId)
: document.createElement('div');
if (toast instanceof HTMLTemplateElement) {
const node = (toast as HTMLTemplateElement).content.cloneNode(true);
toast = ((node as HTMLElement).firstElementChild as HTMLElement);
}
toast.classList.add('toast');
toast.setAttribute('role', 'alert');
toast.setAttribute('aria-live', 'assertive');
Expand Down Expand Up @@ -281,7 +285,7 @@ export class Toast {
this.options.completeCallback();
}
// Remove toast from DOM
if (!this.options.toastId) {
if (this.el.id != this.options.toastId) {
this.el.remove();
Toast._toasts.splice(Toast._toasts.indexOf(this), 1);
if (Toast._toasts.length === 0) {
Expand Down

0 comments on commit 2a2dd9b

Please sign in to comment.