@@ -6,12 +6,16 @@ import {
66 Directive ,
77 AfterViewInit ,
88 Inject ,
9- NgZone
9+ NgZone ,
10+ Renderer2 ,
11+ PLATFORM_ID ,
12+ inject
1013} from '@angular/core' ;
1114import { DOCUMENT } from '@angular/common' ;
1215import { Subject } from 'rxjs' ;
1316import { takeUntil , throttleTime } from 'rxjs/operators' ;
1417import { resizeObservable , PlatformUtil } from '../../core/utils' ;
18+ import { isPlatformBrowser } from '@angular/common' ;
1519
1620@Directive ( {
1721 selector : '[igxVirtualHelperBase]' ,
@@ -27,13 +31,16 @@ export class VirtualHelperBaseDirective implements OnDestroy, AfterViewInit {
2731 private _afterViewInit = false ;
2832 private _scrollNativeSize : number ;
2933 private _detached = false ;
34+ protected renderer = inject ( Renderer2 ) ;
35+ protected platformId = inject ( PLATFORM_ID ) ;
36+ protected ngZone = inject ( NgZone ) ;
3037
3138 constructor (
3239 public elementRef : ElementRef < HTMLElement > ,
3340 public cdr : ChangeDetectorRef ,
3441 protected _zone : NgZone ,
3542 @Inject ( DOCUMENT ) public document : any ,
36- protected platformUtil : PlatformUtil ,
43+ protected platformUtil : PlatformUtil
3744 ) {
3845 this . _scrollNativeSize = this . calculateScrollNativeSize ( ) ;
3946 }
@@ -104,6 +111,34 @@ export class VirtualHelperBaseDirective implements OnDestroy, AfterViewInit {
104111 return this . document . body . contains ( this . nativeElement ) ;
105112 }
106113
114+ private toggleClass ( element : HTMLElement , className : string , shouldHaveClass : boolean ) : void {
115+ if ( shouldHaveClass ) {
116+ this . renderer . addClass ( element , className ) ;
117+ } else {
118+ this . renderer . removeClass ( element , className ) ;
119+ }
120+ }
121+
122+ private updateScrollbarClass ( ) {
123+ if ( ! isPlatformBrowser ( this . platformId ) ) {
124+ return ;
125+ }
126+
127+ this . ngZone . runOutsideAngular ( ( ) => {
128+ requestAnimationFrame ( ( ) => {
129+ const el = this . nativeElement ;
130+ const hasScrollbar = el . scrollHeight > el . clientHeight ;
131+ const prevSibling = el . previousElementSibling as HTMLElement | null ;
132+ const scrollbarClass = 'igx-display-container--scrollbar' ;
133+
134+ if ( prevSibling ?. tagName . toLowerCase ( ) === 'igx-display-container' ) {
135+ this . toggleClass ( prevSibling , scrollbarClass , hasScrollbar ) ;
136+ }
137+ } ) ;
138+ } ) ;
139+ }
140+
141+
107142 protected handleMutations ( event ) {
108143 const hasSize = ! ( event [ 0 ] . contentRect . height === 0 && event [ 0 ] . contentRect . width === 0 ) ;
109144 if ( ! hasSize && ! this . isAttachedToDom ) {
@@ -113,6 +148,8 @@ export class VirtualHelperBaseDirective implements OnDestroy, AfterViewInit {
113148 // attached back now.
114149 this . restoreScroll ( ) ;
115150 }
151+
152+ this . updateScrollbarClass ( ) ;
116153 }
117154
118155 protected restoreScroll ( ) { }
0 commit comments