JakeSidSmith / react-reorder

Drag & drop, touch enabled, reorderable / sortable list, React component
https://jakesidsmith.github.io/react-reorder/
MIT License
218 stars 58 forks source link

Can't disable auto scroll #104

Closed Moebits closed 3 years ago

Moebits commented 3 years ago

Hello, I want to disable auto scroll but it doesn't seem to be working. I wanted to implement by own auto scrolling because I find the default to be way too fast, and because it didn't seem to work when scrolling down. I am on version 3.0.0-alpha.7.

Code:

const reorder = (event: React.MouseEvent, from: number, to: number) => {
        setContainers((prev) => {
            const newState = [...prev]
            newState.splice(to, 0, newState.splice(from, 1)[0])
            return newState
        })
}

return (
        <Reorder reorderId="file-containers" component="ul" autoScroll={false} holdTime={50} onReorder={reorder}>{
            containers.map((c) => (
                <li key={c.id}>
                    {c.jsx}
                </li>
            ))
        }</Reorder>
)
JakeSidSmith commented 3 years ago

Hey, just to let you know this hasn't gone unnoticed. I have a post-it on my desk to take a look at it.

Feel free to fork and try to find a solution yourself in the meantime. You'll need to branch from rework.

JakeSidSmith commented 3 years ago

I cannot reproduce this using the examples in the readme.

I've tried setting autoScroll={false} on the kanban and horizontal lock examples, and it successfully prevents the auto scrolling.

Are you perhaps using a browser that is doing additional scrolling for you? Can you give me any more details, or set up a small repo with an example of it not working?

Moebits commented 3 years ago

Are you perhaps using a browser that is doing additional scrolling for you? Can you give me any more details, or set up a small repo with an example of it not working?

Yeah, I created a test repo here: https://github.com/Tenpi/autoscroll-example (Run with commands npm install and npm start)

I am using this with electron, so I am actually not 100% sure if the problem is from this package, or if it's a bug with electron itself.

With autoScroll={false}, it stops scrolling down, but you can still scroll up. With autoScroll={true}, you can scroll down, but scrolling up is at least 2x faster than scrolling down, which is the problem that I wanted to fix. My intention was to disable auto-scrolling in order to implement my own version that is a little slower.

JakeSidSmith commented 3 years ago

Oooh, this gives me an idea. I think I had an issue similar to this recently. It's something to do with how browsers handle overflow and new content loading in: https://developer.mozilla.org/en-US/docs/Web/CSS/overflow-anchor

If you set overflow-anchor: none on your scrollable element it might fix it... or make it worse. XD

I don't have time to look right now, but may do later today.

Moebits commented 3 years ago

If you set overflow-anchor: none on your scrollable element it might fix it... or make it worse. XD

Thanks! This fixed it. So it was just a CSS issue, I had to disable the scroll anchoring for every element.

* {
  overflow-anchor: none;
}
JakeSidSmith commented 3 years ago

Awesome, glad that's sorted it. 😁

I'll have to add something to the examples/readme.

JakeSidSmith commented 3 years ago

Hopefully you won't need to implement your own scrolling now too. 😉