Skip to content

Commit 8f30110

Browse files
authored
fix(vhelper): fix padding only when vhelper scrollbar is visible (#15973)
1 parent 077b586 commit 8f30110

File tree

4 files changed

+55
-6
lines changed

4 files changed

+55
-6
lines changed

projects/igniteui-angular/src/lib/core/styles/components/drop-down/_drop-down-theme.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@
243243
-webkit-overflow-scrolling: touch;
244244
position: relative;
245245

246-
igx-display-container {
246+
.igx-display-container--scrollbar {
247247
padding-inline-end: var(--vhelper-scrollbar-size);
248248
}
249249
}

projects/igniteui-angular/src/lib/directives/for-of/base.helper.component.ts

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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';
1114
import { DOCUMENT } from '@angular/common';
1215
import { Subject } from 'rxjs';
1316
import { takeUntil, throttleTime } from 'rxjs/operators';
1417
import { 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() {}

projects/igniteui-angular/src/lib/directives/for-of/horizontal.virtual.helper.component.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@ export class HVirtualHelperComponent extends VirtualHelperBaseDirective {
1919
@HostBinding('class')
2020
public cssClasses = 'igx-vhelper--horizontal';
2121

22-
constructor(elementRef: ElementRef, cdr: ChangeDetectorRef, zone: NgZone, @Inject(DOCUMENT) document, platformUtil: PlatformUtil) {
22+
constructor(
23+
elementRef: ElementRef,
24+
cdr: ChangeDetectorRef,
25+
zone: NgZone,
26+
@Inject(DOCUMENT) document: any,
27+
platformUtil: PlatformUtil
28+
) {
2329
super(elementRef, cdr, zone, document, platformUtil);
2430
}
2531

projects/igniteui-angular/src/lib/directives/for-of/virtual.helper.component.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Component, ElementRef, HostBinding, Input, ViewChild, ViewContainerRef,
2-
ChangeDetectorRef, OnDestroy, OnInit, Inject, NgZone } from '@angular/core';
2+
ChangeDetectorRef, OnDestroy, OnInit, Inject, NgZone} from '@angular/core';
33
import { VirtualHelperBaseDirective } from './base.helper.component';
44
import { DOCUMENT } from '@angular/common';
55
import { PlatformUtil } from '../../core/utils';
@@ -21,7 +21,13 @@ export class VirtualHelperComponent extends VirtualHelperBaseDirective implement
2121
@HostBinding('class')
2222
public cssClasses = 'igx-vhelper--vertical';
2323

24-
constructor(elementRef: ElementRef, cdr: ChangeDetectorRef, zone: NgZone, @Inject(DOCUMENT) document, platformUtil: PlatformUtil) {
24+
constructor(
25+
elementRef: ElementRef,
26+
cdr: ChangeDetectorRef,
27+
zone: NgZone,
28+
@Inject(DOCUMENT) document: any,
29+
platformUtil: PlatformUtil,
30+
) {
2531
super(elementRef, cdr, zone, document, platformUtil);
2632
}
2733

0 commit comments

Comments
 (0)