66 * found in the LICENSE file at https://angular.io/license
77 */
88
9+ import { Platform } from '@angular/cdk/platform' ;
910import {
1011 ChangeDetectionStrategy ,
1112 Component ,
@@ -19,6 +20,7 @@ import {
1920 SimpleChanges ,
2021 OnDestroy ,
2122 AfterViewChecked ,
23+ inject ,
2224} from '@angular/core' ;
2325import { take } from 'rxjs/operators' ;
2426
@@ -71,6 +73,8 @@ let calendarBodyId = 1;
7173 changeDetection : ChangeDetectionStrategy . OnPush ,
7274} )
7375export class MatCalendarBody < D = any > implements OnChanges , OnDestroy , AfterViewChecked {
76+ private _platform = inject ( Platform ) ;
77+
7478 /**
7579 * Used to skip the next focus event when rendering the preview range.
7680 * We need a flag like this, because some browsers fire focus events asynchronously.
@@ -177,8 +181,11 @@ export class MatCalendarBody<D = any> implements OnChanges, OnDestroy, AfterView
177181 element . addEventListener ( 'blur' , this . _leaveHandler , true ) ;
178182 element . addEventListener ( 'mousedown' , this . _mousedownHandler ) ;
179183 element . addEventListener ( 'touchstart' , this . _mousedownHandler ) ;
180- window . addEventListener ( 'mouseup' , this . _mouseupHandler ) ;
181- window . addEventListener ( 'touchend' , this . _touchendHandler ) ;
184+
185+ if ( this . _platform . isBrowser ) {
186+ window . addEventListener ( 'mouseup' , this . _mouseupHandler ) ;
187+ window . addEventListener ( 'touchend' , this . _touchendHandler ) ;
188+ }
182189 } ) ;
183190 }
184191
@@ -232,8 +239,11 @@ export class MatCalendarBody<D = any> implements OnChanges, OnDestroy, AfterView
232239 element . removeEventListener ( 'blur' , this . _leaveHandler , true ) ;
233240 element . removeEventListener ( 'mousedown' , this . _mousedownHandler ) ;
234241 element . removeEventListener ( 'touchstart' , this . _mousedownHandler ) ;
235- window . removeEventListener ( 'mouseup' , this . _mouseupHandler ) ;
236- window . removeEventListener ( 'touchend' , this . _touchendHandler ) ;
242+
243+ if ( this . _platform . isBrowser ) {
244+ window . removeEventListener ( 'mouseup' , this . _mouseupHandler ) ;
245+ window . removeEventListener ( 'touchend' , this . _touchendHandler ) ;
246+ }
237247 }
238248
239249 /** Returns whether a cell is active. */
0 commit comments