@@ -6,12 +6,15 @@ import {
66 Directive ,
77 AfterViewInit ,
88 Inject ,
9- NgZone
9+ NgZone ,
10+ Renderer2 ,
11+ PLATFORM_ID
1012} from '@angular/core' ;
1113import { DOCUMENT } from '@angular/common' ;
1214import { Subject } from 'rxjs' ;
1315import { takeUntil , throttleTime } from 'rxjs/operators' ;
1416import { resizeObservable , PlatformUtil } from '../../core/utils' ;
17+ import { isPlatformBrowser } from '@angular/common' ;
1518
1619@Directive ( {
1720 selector : '[igxVirtualHelperBase]' ,
@@ -34,6 +37,9 @@ export class VirtualHelperBaseDirective implements OnDestroy, AfterViewInit {
3437 protected _zone : NgZone ,
3538 @Inject ( DOCUMENT ) public document : any ,
3639 protected platformUtil : PlatformUtil ,
40+ private renderer : Renderer2 ,
41+ @Inject ( PLATFORM_ID ) private platformId : Object ,
42+ private ngZone : NgZone
3743 ) {
3844 this . _scrollNativeSize = this . calculateScrollNativeSize ( ) ;
3945 }
@@ -104,25 +110,31 @@ export class VirtualHelperBaseDirective implements OnDestroy, AfterViewInit {
104110 return this . document . body . contains ( this . nativeElement ) ;
105111 }
106112
113+ private toggleClass ( element : HTMLElement , className : string , add : boolean ) : void {
114+ if ( ! element ) return ;
115+ add ? this . renderer . addClass ( element , className ) : this . renderer . removeClass ( element , className ) ;
116+ }
117+
107118 private updateScrollbarClass ( ) {
108- requestAnimationFrame ( ( ) => {
109- const hasScrollbar = this . nativeElement . scrollHeight > this . nativeElement . clientHeight ;
110- const prevSibling = this . nativeElement . previousElementSibling as HTMLElement | null ;
111-
112- if ( hasScrollbar ) {
113- this . nativeElement . classList . add ( 'has-scrollbar' ) ;
114- if ( prevSibling ?. tagName . toLowerCase ( ) === 'igx-display-container' ) {
115- prevSibling . classList . add ( 'has-scrollbar' ) ;
116- }
117- } else {
118- this . nativeElement . classList . remove ( 'has-scrollbar' ) ;
119- if ( prevSibling ?. tagName . toLowerCase ( ) === 'igx-display-container' ) {
120- prevSibling . classList . remove ( 'has-scrollbar' ) ;
121- }
119+ if ( ! isPlatformBrowser ( this . platformId ) ) {
120+ return ;
121+ }
122+
123+ this . ngZone . runOutsideAngular ( ( ) => {
124+ requestAnimationFrame ( ( ) => {
125+ const el = this . nativeElement ;
126+ const hasScrollbar = el . scrollHeight > el . clientHeight ;
127+ const prevSibling = el . previousElementSibling as HTMLElement | null ;
128+ const scrollbarClass = 'igx-display-container--scrollbar' ;
129+
130+ if ( prevSibling ?. tagName . toLowerCase ( ) === 'igx-display-container' ) {
131+ this . toggleClass ( prevSibling , scrollbarClass , hasScrollbar ) ;
122132 }
133+ } ) ;
123134 } ) ;
124135 }
125136
137+
126138 protected handleMutations ( event ) {
127139 const hasSize = ! ( event [ 0 ] . contentRect . height === 0 && event [ 0 ] . contentRect . width === 0 ) ;
128140 if ( ! hasSize && ! this . isAttachedToDom ) {
0 commit comments