KingSora / OverlayScrollbars

A javascript scrollbar plugin that hides the native scrollbars, provides custom styleable overlay scrollbars, and preserves the native functionality and feel.
https://kingsora.github.io/OverlayScrollbars
MIT License
3.84k stars 214 forks source link

Angular app freezes when using ngbDropdown with OverlayScrollbars #591

Closed Take-Limeship closed 10 months ago

Take-Limeship commented 10 months ago

Describe the bug In Angular when using OverlayScrollbars with a target to a component with a ngbDropdown the app freezes.

To Reproduce Steps to reproduce the behavior:

  1. Go to https://stackblitz.com/edit/angular-ivy-vnrqsj?file=src%2Fapp%2Fapp.component.html,src%2Fapp%2Fapp.component.ts
  2. Click on the Dropdown above
  3. Notice how the whole app is not responsive anymore
  4. The only way I found to try again was to fork the project in StackBlitz

Expected behavior It should be possible to initialize the OverlayScrollbars to a component containing a ngbDropdown without errors.

Additional context We also tried ignoring all mutations and upping the debounce timeout with no avail. Is there something we missed here? Thanks in advance!

KingSora commented 10 months ago

Good day @Take-Limeship :)

I'll take a look as soon as I have time

KingSora commented 10 months ago

@Take-Limeship You have to initialize the plugin outside of the ngZone:

// from your example
this.ngZone.runOutsideAngular(() => {
  OverlayScrollbars(
    {
      target: document.querySelector(
        'scrollbartest-nx-welcome'
      ) as HTMLElement,
      // target: document.body,
      elements: {
        // viewport: document.querySelector('#scroll') as HTMLElement,
      },
    },
    this.defaultOptions
  );
});

Here is a working example: https://stackblitz.com/edit/angular-ivy-4k2pe6?file=src%2Fapp%2Fapp.component.html,src%2Fapp%2Fapp.component.ts

Take-Limeship commented 10 months ago

That solved it, thank you very much! :)