components icon indicating copy to clipboard operation
components copied to clipboard

cdk-virtual-scroll-viewport - support window scroll

Open abeymg opened this issue 8 years ago • 65 comments

Bug, feature request, or proposal:

Feature request

What is the expected behavior?

Allow the scroll of the cdk-virtual-scroll-viewport to be controlled by the top level window scrollbar.

See example at the link below. (Go to that page and click on parent scroll to see desired behavior) https://rintoj.github.io/ngx-virtual-scroller

Another example of window scrolling in the context of virtual scrolling https://bvaughn.github.io/react-virtualized/#/components/WindowScroller

What is the current behavior?

Specifying a parent scroll does not seem to be supported, from what I can tell.

What is the use-case or motivation for changing an existing behavior?

Having a single top level window/page scroll is standard in a lot of SPAs. The virtual-scroll would be a lot more useful in these cases, if it could use the same scroll bar, otherwise often times you end up with two scrollbars (one for the virt-scroll and the other for the page, or else a smaller inset container for the virt-scroll with a scrollbar), which is less than ideal.

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

Angular: 7.0.1 Material: 7.0.2

Is there anything else we should know?

abeymg avatar Oct 29 '18 19:10 abeymg

That would be very useful!

LeParadoxHD avatar Nov 03 '18 13:11 LeParadoxHD

+1

vahidvdn avatar Nov 12 '18 15:11 vahidvdn

This should definitely be implemented soon!

flolu avatar Jan 03 '19 09:01 flolu

mark to track status. This will be awesome!

wunaidage avatar Jan 03 '19 20:01 wunaidage

@mmalerba I did a small POC to support both window and closest relative parent virtual scrolling.

Actually it's not yet ready for merge. It's still missing tests, examples, and even implementations... But at least it gives a proposal for the implementation. I would be really interested to get your feedback.

In my use-case it fits well. Hope you appreciate.

Here is a demo: demo-virtual-scroll

Kind regards,

rmedaer avatar Jan 09 '19 10:01 rmedaer

@rmedaer sure, I can take a look. Can you link me to the branch where you're working?

mmalerba avatar Jan 09 '19 18:01 mmalerba

Yeah ! I committed on master branch in my fork. I know it's bad but again my plan was just to do a test and it became probably more ..

The dev-app (demo) contains an example.

rmedaer avatar Jan 09 '19 18:01 rmedaer

@rmedaer Overall I like the approach, though parts of the implementation I'm not too sure about. I also think we could make the nested viewport more flexible by either making a directive that can be used to mark the parent, or using an @Input() that lets the user specify the scrolling container (e.g. viewportRoot=".some-ancestor-element"), rather than just assuming it's the direct parent.

@jelbourn Do you have any thoughts about this proposal?

mmalerba avatar Jan 10 '19 17:01 mmalerba

Could you summarize the approach?

jelbourn avatar Jan 10 '19 17:01 jelbourn

Actually, my approach is to decouple the viewport and its container. Then I provide somehow the container to the viewport which will use its API to calculate scroll offset and so on. Here is the container's interface:

export interface VirtualScrollContainerRef {
  measureScrollOffset(from: 'top' | 'left' | 'right' | 'bottom' | 'start' | 'end'): number;
  measureContainerSize(orientation: 'horizontal' | 'vertical'): number;
  getViewportSize(contentSize: number): string | null;
  scrollTo(options: ExtendedScrollToOptions): any;
  elementScrolled(): Observable<Event>;
}

As you can see this interface is implementing more or less the same then CdkScrollable (there is no need of ElementRef).

In my POC I "provide" the container ref to the viewport using a directive that you have to apply on viewport. But as @mmalerba said, we could also use a DOM reference. We could even create a directive that you apply on parent (container) element which has to scroll.

Currently my prototype has 3 ContainerRef directives:

  • CdkVirtualScrollDefaultViewport: same behavior then current impl; we are scrolling into the viewport.
  • CdkVirtualScrollNestedViewport: use the closest relative parent as container => works well with offsetTop property.
  • CdkVirtualScrollWindowViewport: use window as container. This one cannot use implementation from CdkScrollable.

rmedaer avatar Jan 18 '19 12:01 rmedaer

This feature is really needed in order to use the Virtual-scroll in real apps.... We would really appreciate if it would be implemented soon.

hezzyg avatar Feb 06 '19 01:02 hezzyg

@hezzyg You can use this module. It's already supported window scroll.

vahidvdn avatar Feb 06 '19 07:02 vahidvdn

@hezzyg otherwise if @mmalerba and/or @jelbourn are OK with my approach, I can deliver a patch ASAP. But I'm still waiting their (no)go to do it (or not). ;-)

rmedaer avatar Feb 06 '19 13:02 rmedaer

@hezzyg otherwise if @mmalerba and/or @jelbourn are OK with my approach, I can deliver a patch ASAP. But I'm still waiting their (no)go to do it (or not). ;-)

Thanks @rmedaer . I do prefer a solution integrated into Angular Material for better support in the future. So I hope your suggestion will get there asap :-)

hezzyg avatar Feb 06 '19 13:02 hezzyg

@hezzyg You can use this module. It's already supported window scroll.

I'll have a look. thanks @vahidvdn

hezzyg avatar Feb 06 '19 14:02 hezzyg

@rmedaer yes I'd like to do this, please send a PR and mention me on it, thanks!

mmalerba avatar Feb 06 '19 22:02 mmalerba

This would be a really useful feature. We are unable to use this at the moment because we have a scrollbar at a different level.

jeetparikh avatar Mar 28 '19 03:03 jeetparikh

@rmedaer @mmalerba

@hezzyg otherwise if @mmalerba and/or @jelbourn are OK with my approach, I can deliver a patch ASAP. But I'm still waiting their (no)go to do it (or not). ;-)

@rmedaer yes I'd like to do this, please send a PR and mention me on it, thanks!

Is there a pull request for the patch? I really need to implement a window scrolling CDK viewport so I'd be grateful for any help!

levitatejay avatar Apr 08 '19 10:04 levitatejay

@mmalerba the PR #14287 is simply introducing the virtual adapter but is there any PR to support scrolling at parent level or window level for cdk-virtual-scroll-viewport?

jeetparikh avatar Apr 08 '19 22:04 jeetparikh

@jeetparikh if it's really urgent, you can take a look at this commit. It's the POC I made to test virtual scrolling on window. Btw I don't have so much time to do a PR for now but at least you can already play with it !

rmedaer avatar Apr 09 '19 14:04 rmedaer