components icon indicating copy to clipboard operation
components copied to clipboard

drag-drop: make the view scroll when trying to move a draggable outside the current view

Open lfroment0 opened this issue 8 years ago • 108 comments

Bug, feature request, or proposal:

When trying to drag a cdkDragItem outside of the view, it does not scroll to show the rest of the cdkDrop div / the rest of the page.

What is the expected behavior?

The view should scroll towards the direction in which the element is being dragged to reveal the rest of the page.

What is the current behavior?

The view doesn't scroll, the droppable item cannot move out of the current view

What are the steps to reproduce?

In the following stackblitz, try to drag an item from the start of the list to the bottom of the list. https://stackblitz.com/edit/angular-emaoau

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

The current behaviour feels very restrictive. you could have to take multiple steps if you want to drag and drop an element in a larger list.

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

  • Angular Cdk 7.0.0 beta to 7.0.0-rc.1

lfroment0 avatar Oct 12 '18 12:10 lfroment0

There's been a TODO for it, but I've mostly held back until now since it's tricky figuring out which element should be scrolled.

crisbeto avatar Oct 12 '18 13:10 crisbeto

Is there any intermediate way to make it work with dom-autoscroller until TODO is addressed? https://github.com/hollowdoor/dom_autoscroller

sanketi avatar Oct 26 '18 19:10 sanketi

@crisbeto I've implemented auto scrolling on CdkDropList in my private fork. It doesn't cover scenarios where the drop list is wider/taller than its scroll parent but it works fine when the drop list fits on the screen. If you think it'd be useful, I can set aside some time to prepare a PR.

JohnKis avatar Nov 16 '18 11:11 JohnKis

@JohnKis the scrolling logic here isn't really the issue. We've held back on implementing it until now, because it's tricky knowing which element we're supposed to scroll.

crisbeto avatar Nov 17 '18 09:11 crisbeto

@crisbeto Understood, just figured I’d ask. Thanks

JohnKis avatar Nov 17 '18 09:11 JohnKis

@crisbeto I think we could use cdk-scrollable as marker for element to scroll

abdulkareemnalband avatar Nov 19 '18 06:11 abdulkareemnalband

Hi guys. Any ideas on when to expect the fix?

ghost avatar Nov 28 '18 08:11 ghost

Hey, any update on this thread?

rimvydas-urbonas avatar Nov 28 '18 14:11 rimvydas-urbonas

Hi. I have a business case where multiple (say more than 10) containers are stacked vertical. So, need to think about this case as well while implementing auto-scrolling. Maybe for this solution it's possible to incorporate event cdkDropListEntered.

varminas avatar Nov 29 '18 12:11 varminas

The cdkDropListEntered event already exists (cdkDragEntered), but doesn't solve the problem.

eg. the case where your dropzones are in a scrollable container and the height of a drop zone is greater than the one of the container, so as only one dropZone is displayed. The supposed cdkDropListEntered event will never be emitted.

Would it be possible to make a CdkdropListGroup aware of it's container, so that it can be conscious of how it should behave when moving an item towards the displayed edges of that container?

lfroment0 avatar Nov 29 '18 12:11 lfroment0

I have been trying to come up with a work-around that does not rely on specific functionality by the component library. My approach was to add transparent divs at the top and the bottom of the scrollable container und to watch for mouseenter/mouseleave events to scroll the container. Unfortunately, this did not work as the framework stops the propagation of these events. I don't know if this behavior could be chanhged more easily than coming up with brand new concepts to deal with the matter.

agent0 avatar Nov 29 '18 14:11 agent0

Any updates so far?

ghost avatar Nov 30 '18 09:11 ghost

I have been trying to come up with a work-around that does not rely on specific functionality by the component library. My approach was to add transparent divs at the top and the bottom of the scrollable container und to watch for mouseenter/mouseleave events to scroll the container. Unfortunately, this did not work as the framework stops the propagation of these events. I don't know if this behavior could be chanhged more easily than coming up with brand new concepts to deal with the matter.

Can you just watch for window.height and window.width and check, if the container extends further, then if it is drag action, then if mouse is down (meaning something is being dragged), then scroll the page accordingly?

ghost avatar Dec 04 '18 08:12 ghost

@aidvb I have a solution but it comes with its own problems see repro example in #14098

abdulkareemnalband avatar Dec 04 '18 09:12 abdulkareemnalband

@aidvb Maybe this would work with scrolling the entire page, in my use case, however, I would like to scroll individual divs. Also, I am not sure if I need browser events to capture the mouse actions and since material cancels the event popagation, I would end up where I started.

agent0 avatar Dec 04 '18 10:12 agent0

@agent0 How's it going to solve the problem?

ghost avatar Dec 07 '18 12:12 ghost

+1 for this

fromage9747 avatar Dec 16 '18 06:12 fromage9747

@aidvb It would not solve the problem as such but it would enable me to implement my own scrolling trigger to scroll the underlying div manually. As it stands now, I cannot detect that the drag is hovering a border area of the div.

agent0 avatar Dec 16 '18 07:12 agent0

+1 for this

RobinBomkampDv avatar Dec 18 '18 10:12 RobinBomkampDv

Any progress on solving this issue?

ghost avatar Dec 20 '18 13:12 ghost