MurhafSousli / ngx-scrollbar

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

`inline-block` scroll content hack causing issues with `relative` positioned content #510

Closed hakimio closed 9 months ago

hakimio commented 1 year ago

Reproduction

Reproduction project attached to this issue. ngx-scrollbar-swiper.zip

Steps to reproduce:

  1. Place swiperjs <swiper> element inside <ng-scrollbar>

Expected Behavior

Swiper content would look the same like when placed inside a overflow: auto block element.

Actual Behavior

ng-scrollbar causes swiper slides to be a lot wider than they are supposed to be.

Additional Info

Changing ng-scroll-content display from inline-block to block fixes the issue.

Environment

MurhafSousli commented 1 year ago

Please use the stackblitz for reproduction!

hakimio commented 1 year ago

Here is CodeSandbox reproduction: https://codesandbox.io/p/sandbox/unruffled-cache-8grp6q?file=%2Fsrc%2Fapp%2Fapp.component.scss%3A19%2C4

MurhafSousli commented 1 year ago

As I remember the inline-block was necessary to make horizontal scroll work properly. with display block it would force fitting parent width.

Your fix should stay at the project level

hakimio commented 1 year ago

EDIT: here is a fix for the example number 5 padding issue:

code {
    display: block;
    padding: 0 10px;
    width: fit-content;
}

Patch: Remove_inline-block_hack.patch

MurhafSousli commented 1 year ago

@hakimio If width: fit-content was applied on ng-scroll-content element instead of display: inline-block, would it also cause the same issue? could you try it?

hakimio commented 1 year ago

Yes, it causes the same issue. Anyway, what kind of issue exactly are you trying to address with those kind of workarounds/hacks?

MurhafSousli commented 1 year ago

Yes, it causes the same issue. Anyway, what kind of issue exactly are you trying to address with those kind of workarounds/hacks?

The content layer is observed for size change using the ResizerObserver if it didn't fit the width of its content, the scrollbar won't be notified to update

MurhafSousli commented 1 year ago

@hakimio I will tackle this by adding width: fit-content only when the viewport is horizontally scrollable

hakimio commented 1 year ago

Sounds good. Thank you.

MurhafSousli commented 1 year ago

@hakimio Could you try if it works fine with the slider if you remove width: fit-content and set position: absolute on the .ng-scroll-content ?

hakimio commented 1 year ago

No, but you can just test it yourself as well. I have provided CodeSandbox reproduction above.

MurhafSousli commented 1 year ago

No, but you can just test it yourself as well. I have provided CodeSandbox reproduction above.

Oh, forgot about that, lol

MurhafSousli commented 9 months ago

Fixed in v14