Skip to content

Commit

Permalink
fix(toast): fixed initial async undefined error (#1039)
Browse files Browse the repository at this point in the history
Co-authored-by: Demirci <ridvan.demirci@siemens.com>
  • Loading branch information
ridvandmrc and Demirci committed Jan 31, 2024
1 parent aa4bdc3 commit 6030480
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions packages/core/src/components/toast/toast-container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,15 @@ export class ToastContainer {
private readonly PREFIX_POSITION_CLASS = 'toast-container--';

get hostContainer() {
return document.getElementById(this.containerId);
return new Promise<HTMLElement>((resolve) => {
const interval = setInterval(() => {
const containerElement = document.getElementById(this.containerId);
if (containerElement) {
clearInterval(interval);
resolve(containerElement);
}
});
});
}

componentDidLoad() {
Expand Down Expand Up @@ -91,9 +99,7 @@ export class ToastContainer {
toast.appendChild(config.message);
}

setTimeout(() => {
this.hostContainer.appendChild(toast);
});
(await this.hostContainer).appendChild(toast);

return {
onClose,
Expand Down

0 comments on commit 6030480

Please sign in to comment.