Skip to content

Commit

Permalink
fix: access document only in browser (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcjulian committed Apr 16, 2024
1 parent 4893228 commit 308a56a
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions libs/ngx-sonner/src/lib/toaster.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 308a56a

Please sign in to comment.