-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
virtual-scroll inside mat-select new values not visible & big space #13087
Comments
Workaround:- https://stackblitz.com/edit/angular-h4xptu-zyj4yh?file=styles.css Added class
and add global styles as below:- In
I think the real solution would be that somehow |
Not quite the workaround above: The above workaround has problems when the overlay is closed and reopened and scrolled in between. When scrolled to a few elements down and the select panel is reopened next time we see a blank space above. This is solved by https://stackblitz.com/edit/angular-h4xptu-kuu5xg?file=app%2Fselect-reset-example.ts
|
Another issue with If the currently selected value is not in the Workaround: Supplement additional
|
Related to #10122 @yogeshgadge Thanks for posting these findings, good stuff to know. |
workarround for mat select using @yogeshgadge s approach with a form control (css in stylus syntax)
with css:
giving the mat-select a panelClass, e.g. custom-mat-select with
|
I just gave the example in the issue desription a quick look - itemSize should be the height of individual items, not the length of the array? Setting a height on the element + [itemSize]=48 works (albeit, it looks a bit crap when there are less than 4 options). |
Also cdk-virtual-scroll-viewport inside a mat-menu doesn't work properly. Sometimes, blank space appears with mouse wheel scrollling. |
@StefanoLucchi Same thing happen to me. And when you reopen the menu it's empty |
@StefanoLucchi @justindiaw I had the same problem, but helped me increasing minBufferPx and maxBufferPx on cdk-virtual-scroll-viewport to eg. 300 and 600 |
A slight change to @yogeshgadge's solution and changing the buffers as suggested by @kubex320 solved all the white space issues.
|
Exactly what I was looking for. Thank you. I was wondering why the panel seems to show white div space when scroll in between and close and reopen again. |
Thanks to those who shared workarounds - it's very helpful! Anyone got the keyboard navigation (up/down arrow keys to browse through the options) working with virtual scrolling? It doesn't scroll when I use keyboard and I couldn't figure out how to get this working. I'm thinking of implementing custom keyboard event handlers for up/down arrow keys and manually setting the virtual scroll position (or the rendered index), but not sure if it's the best way to do as mat-select already has the keyboard handlers implemented. Would appreciate any inputs on this :) |
I had a issue with only seeing a white dropdown after I selected a option and reopened the select. This only happened when I selected an option where I needed to scroll to get to. I solved it purely in the template and just want to leave this here for reference in case someone else stumbles across this: <mat-form-field>
<mat-select [formControl]="form" placeholder="State" class="virtual-scroll"
(openedChange)="scrollViewport.scrollToIndex(states.indexOf(form.value))">
<cdk-virtual-scroll-viewport itemSize="10" #scrollViewport>
<mat-option *cdkVirtualFor="let state of states" [value]="state">
{{state}}
</mat-option>
</cdk-virtual-scroll-viewport>
</mat-select>
</mat-form-field> https://stackblitz.com/edit/angular-h4xptu-mmtdbj?file=app%2Fselect-reset-example.html |
Another smaller issue I saw here was that mat-active is being inappropriately assigned to options in the virtual scrolling component. |
Did you ever figure out a way to do this? I'm currently trying to implement this, but it seems like set scrollToIndex or setRenderedRange stops the next option from being selected/highlighted/focused. |
@dickinr I found that all of the solutions above result in a hacky solution. I looked at the source code, but couldn't find a reasonable way of getting the virtual scrolling to work, without rewriting the component. I think it would be best to either create a custom component, or to use a different UI component. Maybe a filtered autocomplete would fit your purposes: https://material.angular.io/components/autocomplete/examples |
Hello, We are using Angular 16 and still facing issue. If we select an item wich is not in default rendered view range (0 to N), the viewport appears blank until a scroll event. Is there some news ? |
Bug, feature request, or proposal:
Bug
What is the expected behavior?
cdk-virtual-scroll-viewport
inside a mat-select or mat-autocomplete should align with the overlay panel.What is the current behavior?
When scrolled
cdkVirtualFor
does not seem to add more elements and moreover shows a big space from last element of the initial set of items to the end.What are the steps to reproduce?
https://stackblitz.com/edit/angular-h4xptu-dgjd87?file=app/select-reset-example.html
What is the use-case or motivation for changing an existing behavior?
Occasionally I run into scenarios where the items in the list are too many and makes the page unresponsive.
Seem-less integration of cdk-virtual-scroll-viewport with other components.
mat-select essentially can handle any number of elements when this works.
Which versions of Angular, Material, OS, TypeScript, browsers are affected?
Is there anything else we should know?
Great work
The text was updated successfully, but these errors were encountered: