MurhafSousli / ngx-scrollbar

Custom overlay-scrollbars with native scrolling mechanism
https://ngx-scrollbar.netlify.app/
MIT License
623 stars 99 forks source link

Position fixed elements are getting cutoff #662

Open Athulkrishnankr opened 2 months ago

Athulkrishnankr commented 2 months ago

Reproduction

I have a dialog window with position fixed. Its working fine if I move the dialog window out of the scrollbar.

Expected Behavior

The dialog window should not get cut off.

Actual Behavior

The window is getting cut off.

Environment

MurhafSousli commented 2 months ago

Please add a reproduction https://stackblitz.com/edit/ngx-scrollbar

Athulkrishnankr commented 2 months ago

I checked the css of the scrollbar, this is the line causing the issue. .ng-scroll-content { contain: content }

When I remove this, it works fine.

MurhafSousli commented 2 months ago

Yes, absolute and fixed elements won't work properly with contain: content wrapper

sharathdaniel commented 2 months ago

Yes, absolute and fixed elements won't work properly with contain: content wrapper

Omg, really? Then what's the solution?

MurhafSousli commented 2 months ago

You said when you remove it, it works! then what's the issue?

montella1507 commented 2 weeks ago

@MurhafSousli we have the same problem.

<ng-scrollbar
    hoverOffset="true"
    orientation="vertical"
    class="w-full flex flex-1 flex-col overflow-y-auto overflow-x-hidden"
>
    <div class="padding scrollViewport">
        <ng-content></ng-content>
    </div>
</ng-scrollbar>

and we have "fixed buttons"

image

The problem is, that contain: content has element with .ng-scroll-content class

image

But when i set contain: none our buttons works, however, ALL scrollbars are bugged now:

image

montella1507 commented 2 weeks ago

Hacked with:


  ::ng-deep > ng-scrollbar {
      .ng-scroll-content {
        contain: none !important;
      }

      scrollbar-y {
        position: fixed !important;
        top: calc(100vh - var(--viewport-height)) !important;
        left: calc(100% - 12px);
      }
    }

in component containng that ng-scrollbar and fixed button.

MurhafSousli commented 2 weeks ago

@montella1507 I think a better solution without a hack, if you place your button outside the scrollbar component and make it absolute to the bottom

<div class="relative-position-container">
  <ng-scrollbar class="full-height" hoverOffset orientation="vertical">
    <ng-content/>
  </ng-scrollbar>

  <button class="absolute-bottom">segment</button>
</div>

If your button is projected via content, you can use

<div class="relative-position-container">
  <ng-scrollbar class="full-height" hoverOffset orientation="vertical">
    <ng-content/>
  </ng-scrollbar>

  <div class="absolute-bottom">
     <ng-content select="button.action-button"/>
  </div>
</div>
montella1507 commented 2 weeks ago

Yeah, however, this is not possible :-/ Those buttons are used inside of the page and they are changes to fixed in mobile resolution

// page component

<ng-scrollbar
   ...
>
    <div class="padding scrollViewport">
        <ng-content></ng-content>
    </div>
</ng-scrollbar>

// layout

<se-top-barr></se-top-bar>
<main>
    <se-menu></se-menu>
    <se-page>
        <router-outlet></router-outlet>
    </se-page>
</main>

// any page loaded "to the" router outlet

<se-breadcrumb></se-breadcrumb>
    <se-page-title-wrapper>
        <se-page-title>
           Hello!
        <se-help-choice></se-help-choice>
    </se-page-title>

    <se-page-buttons> <<<<<< those fixed buttons
        <se-button
            Nová automatizace
        </se-button>
    </se-page-buttons>
</se-page-title-wrapper>

<se-page-content>
  content itseld
</se-page-content>

So particular page is loaded "inside of the page" (inside of the scrollbar). I can create some kind of workaround with "sending" of template to 2 different places... however this is way more work to do..

BTW why is contain: content so neccessary there? i though it is only usually used as an optimization.

MurhafSousli commented 2 weeks ago

@montella1507 The plugin uses the sticky position technique to hold the scrollbars position while scrolling the viewport. the advantage of using sticky that you are able to scroll via mouse wheel while pointer is over the scrollbar, that was not possible when you use absolute positioning because the scrollbars would block the wheel event while pointer is over the scrollbar.

Maybe this is a absurd detail and maybe most users don't care about it. but I wanted to mimic the original scrollbar functionality.

So this was a solution an overwhelming options we provided in older versions called pointerEventsMethod where each option had pros and cons.

contain: content is required in this technique, but I cannot remember the exact reason ATM.

I am looking forward to find a better way, hopefully when I find sometime soon.