MurhafSousli / ngx-scrollbar

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

Issue in ngx-scrollbar with mat-select of angular-material #537

Closed vartikaagrawal411 closed 8 months ago

vartikaagrawal411 commented 10 months ago

Reproduction

I need to use ngx scrollbar inside mat select component. mat select get adjusted according to content given on top or bottom. So, I am giving max-height like this image and autoHeightDisabled= false , image

but, mat select dropdown is not adjusting it's position on top, and is getting clipped image

Without using ngx-scrollbar mat-select is working as expected.

Use StackBlitz to reproduce your issue: https://stackblitz.com/edit/ngx-scrollbar-jpa7wb?file=src%2Fapp%2Fscroll-event-example%2Fscroll-event-example.html,src%2Fapp%2Fscroll-event-example%2Fscroll-event-example.module.ts,src%2Fapp%2Fscroll-event-example%2Fscroll-event-example.scss,src%2Fapp%2Fapp.component.html,src%2Fapp%2Fapp.component.css

Steps to reproduce:

  1. Go to Scroll-event section
  2. see the behavior in given dropdown

Expected Behavior

mat select dropdown should adjust itself on top so that content don't get clipped

Actual Behavior

mat select dropdown is not getting adjusted on top and is getting clipped

Environment

MurhafSousli commented 10 months ago

The MatSelect component cannot maintain the scroll position since its scrollable viewport has changed.

Here is a workaround that uses the opened output to manually scroll to the selected item, but it isn't ideal since there is a tiny delay from the opened output stackblitz

Maybe you can find a solution with a faster event like combining click event with selected output and scroll to element position asap

MurhafSousli commented 10 months ago

I am working on a directive the uses the original viewport but its still under development.

vartikaagrawal411 commented 10 months ago

Hi, Thanks for your suggestion but the workaround you have mentioned will probably not applicable in my case.

The issue is not related to the scroll behavior change on click of dropdown. The ideal behavior is the dropdown options overlay to open with proper position so that the content is visible in the view port. (Current behavior is dropdown options overlay is opening on the lower side of the box, and due to this options are getting trimmed/not visible. Ideally it would have auto adjusted and came on the upper side of the box)

Issue image

Expected

image

MurhafSousli commented 10 months ago

In the stackblitz it works as expected! it opens at the upper side when there is not enough space at the bottom.

I am not sure if I understood your issue, could you add two select controls next to each other and show the difference

vartikaagrawal411 commented 10 months ago

yes I have added both expected and current behavior dropdowns in scroll event page.. one with [autoHeightDisabled]="false" and one without it.. please check it now

MurhafSousli commented 10 months ago

Now I see it, yea so the mat-select decides where the panel should go, and initially when autoHeight is enabled it won't detect its height. why is auto-height needed in your use case?

vartikaagrawal411 commented 10 months ago

Incase I don't give [autoHeightDisabled]="false", I need to specify height to my ngx scrollbar.. Without it my mat-select come as blank. I need to get data in mat-select from an Api, now data can be 1 or 16 so I don't want to give specific height to my scrollbar as it will create extra space in it. This is the reason I am using [autoHeightDisabled]="false" without height. I have made some changes in stackblitz.. you can see the difference between the three form fields.

MurhafSousli commented 10 months ago

This will be fixed in the next version

skinet2009 commented 9 months ago

@MurhafSousli Please tell me when the new version is planned to be released?

MurhafSousli commented 9 months ago

@MurhafSousli Please tell me when the new version is planned to be released?

@skinet2009 Its almost done, needs to update the documentation and release, either by the end of this weekend or next week. I will ping you here.

skinet2009 commented 8 months ago

@MurhafSousli Please tell me, will there be support for the solution for Angular 16?

MurhafSousli commented 8 months ago

I am not sure, try it out!

Add the following in your package.json

 "overrides": {
    "ngx-scrollbar": {
        "@angular/common": "^16.0.0",
        "@angular/core": "^16.0.0",
        "@angular/cdk": "^16.0.0"
     }
  }
skinet2009 commented 8 months ago

I am not sure, try it out!

Add the following in your package.json

 "overrides": {
    "ngx-scrollbar": {
        "@angular/common": "^16.0.0",
        "@angular/core": "^16.0.0",
        "@angular/cdk": "^16.0.0"
     }
  }

Unfortunately, Angular does not support using libraries with a higher version of Angular. Can't you apply the solution to fix this bug for ngx-scrollbar version 13?

MurhafSousli commented 8 months ago

No, its not possible.