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

Using scrollIntoView does not update the scroll.offset of ScrollControls #772

Open
arthurescapegit opened this issue Feb 19, 2022 · 4 comments
Labels
bug Something isn't working

Comments

@arthurescapegit
Copy link

  • three version: 0.133.1
  • @react-three/fiber version: 7.0.16
  • @react-three/drei version: 7.16.6
  • node version: (codesandbox default)
  • npm (or yarn) version: (codesandbox default)

Problem description:

When using the scrollIntoview function to get to an element contained in ScrollControls, the content scrolls in unexpected ways, creating an buggy setup. It seems like the onScroll method inside ScrollControls.tsx is not called when using scrollIntoView, therefore the scroll.offset value is not updating, resulting in the weird behaviors.

Relevant code:

Here is a sandbox to see the problem:
ScrollControls with minimap scrollintoview bug

Suggested solution:

By looking around in the ScrollControls.tsx, it seems clear that onScroll (line 144) is not called when using scrollintoview. I tried creating custom events to fire when a link is clicked such as: scroll.el.dispatchevent(new customevent('scroll')), but the behavior seems to still screw up... not exactly sure how to go about this. I would imagine that a method one can call to scrollTo somewhere would be a good addition to the awesome ScrollControls!

@arthurescapegit arthurescapegit added the bug Something isn't working label Feb 19, 2022
@psycho-baller
Copy link

hey @arthurescapegit
Facing the same problem as you did. Did you find any solution for the lack of a scrollTo func?

@psycho-baller
Copy link

I kinda found a workaround for this issue. you can find the code here. I made a tutorial video that explains the code here

@RobeSantoro
Copy link

@RobeSantoro
Copy link

Check this lib, too:
https://github.com/14islands/r3f-scroll-rig/tree/master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants