Update perfect scrollbar on document click...

This isn't the most elegant solution but there is no other way
of knowing when the contents of the scrollable container changes.
Therefore, we update scrollbars on every document click.
This commit is contained in:
Sercan Yemen 2018-01-09 11:30:11 +03:00
parent 416f1997a9
commit ba49621e79

View File

@ -1,8 +1,8 @@
import { AfterViewInit, Directive, ElementRef, OnDestroy, OnInit } from '@angular/core'; import { AfterViewInit, Directive, ElementRef, HostListener, OnDestroy } from '@angular/core';
import PerfectScrollbar from 'perfect-scrollbar';
import { FuseConfigService } from '../../services/config.service'; import { FuseConfigService } from '../../services/config.service';
import { Subscription } from 'rxjs/Subscription'; import { Subscription } from 'rxjs/Subscription';
import { Platform } from '@angular/cdk/platform'; import { Platform } from '@angular/cdk/platform';
import PerfectScrollbar from 'perfect-scrollbar';
@Directive({ @Directive({
selector: '[fusePerfectScrollbar]' selector: '[fusePerfectScrollbar]'
@ -13,7 +13,7 @@ export class FusePerfectScrollbarDirective implements AfterViewInit, OnDestroy
isDisableCustomScrollbars = false; isDisableCustomScrollbars = false;
isMobile = false; isMobile = false;
isInitialized = true; isInitialized = true;
ps; ps: PerfectScrollbar;
constructor( constructor(
public element: ElementRef, public element: ElementRef,
@ -62,6 +62,21 @@ export class FusePerfectScrollbarDirective implements AfterViewInit, OnDestroy
this.ps.destroy(); this.ps.destroy();
} }
@HostListener('document:click', ['$event'])
documentClick(event: Event): void
{
if ( !this.isInitialized || !this.ps )
{
return;
}
// Update the scrollbar on document click..
// This isn't the most elegant solution but there is no other way
// of knowing when the contents of the scrollable container changes.
// Therefore, we update scrollbars on every document click.
this.ps.update();
}
update() update()
{ {
if ( !this.isInitialized ) if ( !this.isInitialized )