fisshy / react-scroll

React scroll component
https://github.com/fisshy/react-scroll/blob/master/README.md
MIT License
4.36k stars 437 forks source link

Stop the navigation to element upon clicking link #536

Open plffy opened 1 year ago

plffy commented 1 year ago

I have explained the complete situation here - https://stackoverflow.com/questions/74753194/react-customise-react-scroll-behaviour.

Can we stop the navigation behaviour on click of Link/Button? I want to use onClick props to navigate to the desired element when clicked but at the same time the correct Link should get active when user scrolls using mouse.

plffy commented 1 year ago

Basically, can we give an option to make Link/Button non-clickable?

fisshy commented 1 year ago

Have you tried CSS for this?

a { pointer-events: none }could potentially fix it

plffy commented 1 year ago

This will block all the actions on Link element. I still need the navigation to work onClick. I did the below changes to solve this:

  1. Copied the code for "Element" and "scroll-link" locally and comment out the below code in "scroll-link"

` /*

Keeping the navigation using default "to" props as optional solves the common problem of last Link element not getting active as the offset is now set differently for onClick and active state transition.

Please let me know if you see any issue with this approach

plffy commented 1 year ago

@fisshy Can we have this support added in the react-scroll? I am happy to raise a PR for this.

This will solve the use-case to set the state active some pixels before the element reaches top and at the same time bring the element to top when clicked.

This is the normal scroll behaviour we generally see in most of the websites.

plffy commented 1 year ago

Any update on this?

fisshy commented 1 year ago

Your always free to make a PR for this, but I will have to try it out and make sure it doesn't break current behaviour.