Skip to content
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

Can't scroll tree while dragging #31057

Open
1 task done
metapone opened this issue Jun 20, 2021 · 8 comments
Open
1 task done

Can't scroll tree while dragging #31057

metapone opened this issue Jun 20, 2021 · 8 comments
Labels

Comments

@metapone
Copy link

metapone commented Jun 20, 2021

  • I have searched the issues of this repository and believe that this is not a duplicate.

Reproduction link

Edit on CodeSandbox

Steps to reproduce

Have a list with enough content to overflow its container, or window.

What is expected?

While dragging, mousewheel could be used to scroll down to currently not visible component.

What is actually happening?

Mousewheel is lock, can't scroll. If user drags the item to the top/bottom of its container, the tree is scrolled but the drag operation is aborted after a few seconds (cursor turned to 'not-allowed' icon). Programmatically scroll the tree has the same result.

Environment Info
antd 4.15.2
React 17.0.2
System Windows 10
Browser Chrome 91
@0407chan
Copy link

0407chan commented Dec 8, 2021

have the same problem.
any updates?

@metapone
Copy link
Author

metapone commented Dec 8, 2021

@0407chan If you want to at least be able to scroll, you can do it like I did. I ended up using 2 hidden divs set on top and bottom of the list with onDragOver event handler to manually scroll the list. You will have to handle special cases like users dropping item outside of the list, or dragging sometimes triggers hover event on list items randomly, but at least the list is scrollable.

@github-actions github-actions bot removed the Inactive label Dec 8, 2021
@0407chan
Copy link

0407chan commented Dec 9, 2021

@metapone thanks for share.
I'll try that.

@0407chan
Copy link

@metapone Have question for you.
how did you move scroll on Virtual List?
I added 2 hidden div width onDragOver but can't move scrollbar in virtual list.
how to handle it?

@metapone
Copy link
Author

@0407chan use a ref or a DOM query to get the virtual list, then use scrollBy. I set y-coord to +-50 but you can adjust it to however you want. Remember to debounce it because onDragOver got fired hundreds of times per second and you don't want the list to be scrolled that fast.

@callmecly
Copy link

const onDragOver = (info) => {
    if (info.event.target) {
        scrollTo(info.event.target);
    }
};

const scrollTo = useCallback(
    throttle((target) => {
        const { bottom: currentBottom, top: currentTop } = target.getBoundingClientRect();
        const { bottom: boxBottom, top: boxTop } = document
            .getElementsByClassName('ant-tree-list-holder')[0]
            .getBoundingClientRect();

        if (currentTop > boxBottom - 48) {
            document.getElementsByClassName('ant-tree-list-holder')[0].scrollTop =
                document.getElementsByClassName('ant-tree-list-holder')[0].scrollTop + 32;
        }

        if (boxTop + 48 > currentBottom) {
            document.getElementsByClassName('ant-tree-list-holder')[0].scrollTop =
                document.getElementsByClassName('ant-tree-list-holder')[0].scrollTop - 32;
        }
    }, 100),
    [treeRef]
);

Here's my implementation for reference!

@canberkakartuna
Copy link

Same problem, any updates?

@Wxh16144
Copy link
Member

Wxh16144 commented Feb 7, 2024

Same problem, any updates? :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants