Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@
-webkit-overflow-scrolling: touch;
position: relative;

igx-display-container {
.igx-display-container--scrollbar {
padding-inline-end: var(--vhelper-scrollbar-size);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import {
AfterViewInit,
Inject,
NgZone,
DOCUMENT
Renderer2,
PLATFORM_ID
} from '@angular/core';
import { Subject } from 'rxjs';
import { takeUntil, throttleTime } from 'rxjs/operators';
import { resizeObservable, PlatformUtil } from '../../core/utils';
import { DOCUMENT, isPlatformBrowser } from '@angular/common';

@Directive({
selector: '[igxVirtualHelperBase]',
Expand All @@ -34,6 +36,9 @@ export class VirtualHelperBaseDirective implements OnDestroy, AfterViewInit {
protected _zone: NgZone,
@Inject(DOCUMENT) public document: any,
protected platformUtil: PlatformUtil,
private renderer: Renderer2,
@Inject(PLATFORM_ID) private platformId: Object,
private ngZone: NgZone
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try to use the inject API so you don't have to also modify all classes that extend the base class.

) {
this._scrollNativeSize = this.calculateScrollNativeSize();
}
Expand Down Expand Up @@ -104,6 +109,31 @@ export class VirtualHelperBaseDirective implements OnDestroy, AfterViewInit {
return this.document.body.contains(this.nativeElement);
}

private toggleClass(element: HTMLElement, className: string, add: boolean): void {
if (!element) return;
add ? this.renderer.addClass(element, className) : this.renderer.removeClass(element, className);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick, but I'd use a regular control flow "if / else" statement here instead of a ternary operator.

}

private updateScrollbarClass() {
if (!isPlatformBrowser(this.platformId)) {
return;
}

this.ngZone.runOutsideAngular(() => {
requestAnimationFrame(() => {
const el = this.nativeElement;
const hasScrollbar = el.scrollHeight > el.clientHeight;
const prevSibling = el.previousElementSibling as HTMLElement | null;
const scrollbarClass = 'igx-display-container--scrollbar';

if (prevSibling?.tagName.toLowerCase() === 'igx-display-container') {
this.toggleClass(prevSibling, scrollbarClass, hasScrollbar);
}
});
});
}


protected handleMutations(event) {
const hasSize = !(event[0].contentRect.height === 0 && event[0].contentRect.width === 0);
if (!hasSize && !this.isAttachedToDom) {
Expand All @@ -113,6 +143,8 @@ export class VirtualHelperBaseDirective implements OnDestroy, AfterViewInit {
// attached back now.
this.restoreScroll();
}

this.updateScrollbarClass();
}

protected restoreScroll() {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Component, ElementRef, HostBinding, Input, ViewChild, ViewContainerRef, ChangeDetectorRef, Inject, NgZone, DOCUMENT } from '@angular/core';
import { Component, ElementRef, HostBinding, Input, ViewChild, ViewContainerRef, ChangeDetectorRef, Inject, NgZone, Renderer2, PLATFORM_ID } from '@angular/core';
import { DOCUMENT } from '@angular/common';
import { VirtualHelperBaseDirective } from './base.helper.component';
import { PlatformUtil } from '../../core/utils';

Expand All @@ -18,8 +19,17 @@ export class HVirtualHelperComponent extends VirtualHelperBaseDirective {
@HostBinding('class')
public cssClasses = 'igx-vhelper--horizontal';

constructor(elementRef: ElementRef, cdr: ChangeDetectorRef, zone: NgZone, @Inject(DOCUMENT) document, platformUtil: PlatformUtil) {
super(elementRef, cdr, zone, document, platformUtil);
constructor(
elementRef: ElementRef,
cdr: ChangeDetectorRef,
zone: NgZone,
@Inject(DOCUMENT) document: any,
platformUtil: PlatformUtil,
renderer: Renderer2,
@Inject(PLATFORM_ID) platformId: Object,
ngZone: NgZone
) {
super(elementRef, cdr, zone, document, platformUtil, renderer, platformId, ngZone);
}

protected override restoreScroll() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Component, ElementRef, HostBinding, Input, ViewChild, ViewContainerRef,
ChangeDetectorRef, OnDestroy, OnInit, Inject, NgZone, DOCUMENT } from '@angular/core';
ChangeDetectorRef, OnDestroy, OnInit, Inject, NgZone, Renderer2,
PLATFORM_ID} from '@angular/core';
import { DOCUMENT } from '@angular/common';
import { VirtualHelperBaseDirective } from './base.helper.component';
import { PlatformUtil } from '../../core/utils';

Expand All @@ -20,8 +22,17 @@ export class VirtualHelperComponent extends VirtualHelperBaseDirective implement
@HostBinding('class')
public cssClasses = 'igx-vhelper--vertical';

constructor(elementRef: ElementRef, cdr: ChangeDetectorRef, zone: NgZone, @Inject(DOCUMENT) document, platformUtil: PlatformUtil) {
super(elementRef, cdr, zone, document, platformUtil);
constructor(
elementRef: ElementRef,
cdr: ChangeDetectorRef,
zone: NgZone,
@Inject(DOCUMENT) document: any,
platformUtil: PlatformUtil,
renderer: Renderer2,
@Inject(PLATFORM_ID) platformId: Object,
ngZone: NgZone
) {
super(elementRef, cdr, zone, document, platformUtil, renderer, platformId, ngZone);
}

public ngOnInit() {
Expand Down
Loading