From 202cdf2ae151cd37f79d09dcba1c12d4be7adb0a Mon Sep 17 00:00:00 2001 From: Marc Stammerjohann <8985933+marcjulian@users.noreply.github.com> Date: Mon, 15 Apr 2024 11:40:45 +0200 Subject: [PATCH] fix: access document only in browser --- libs/ngx-sonner/src/lib/toaster.component.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/ngx-sonner/src/lib/toaster.component.ts b/libs/ngx-sonner/src/lib/toaster.component.ts index cf4591e..ac16299 100644 --- a/libs/ngx-sonner/src/lib/toaster.component.ts +++ b/libs/ngx-sonner/src/lib/toaster.component.ts @@ -180,9 +180,9 @@ export class NgxSonnerToaster implements OnDestroy { constructor() { this.reset(); - document.addEventListener('keydown', this.handleKeydown); if (isPlatformBrowser(this.platformId)) { + document.addEventListener('keydown', this.handleKeydown); window .matchMedia('(prefers-color-scheme: dark)') .addEventListener('change', this.handleThemePreferenceChange); @@ -201,8 +201,8 @@ export class NgxSonnerToaster implements OnDestroy { } ngOnDestroy() { - document.removeEventListener('keydown', this.handleKeydown); if (isPlatformBrowser(this.platformId)) { + document.removeEventListener('keydown', this.handleKeydown); window .matchMedia('(prefers-color-scheme: dark)') .removeEventListener('change', this.handleThemePreferenceChange);