Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Position fixed elements are getting cutoff #662

Open
Athulkrishnankr opened this issue Sep 26, 2024 · 10 comments
Open

Position fixed elements are getting cutoff #662

Athulkrishnankr opened this issue Sep 26, 2024 · 10 comments
Labels

Comments

@Athulkrishnankr
Copy link

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

  • Angular:18.2.1
  • ngx-scrollbar: 15.1.3
  • Browser(s): Chrome
  • Operating System: Windows 10
@MurhafSousli
Copy link
Owner

MurhafSousli commented Sep 26, 2024

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

@Athulkrishnankr
Copy link
Author

Athulkrishnankr commented Sep 27, 2024

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
Copy link
Owner

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

@sharathdaniel
Copy link

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

Omg, really? Then what's the solution?

@MurhafSousli
Copy link
Owner

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

@montella1507
Copy link

montella1507 commented Nov 14, 2024

@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
Copy link

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
Copy link
Owner

MurhafSousli commented Nov 14, 2024

@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
Copy link

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
Copy link
Owner

MurhafSousli commented Nov 15, 2024

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants