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

scroll to item as a prop #68

Open
bharatpatil opened this issue May 25, 2021 · 2 comments
Open

scroll to item as a prop #68

bharatpatil opened this issue May 25, 2021 · 2 comments

Comments

@bharatpatil
Copy link

Hi @Lodin, can we add a initialScrollToItem prop (which takes an id) in addition to scrollToItem method. The context is, I'm using this react-vtree in a popover component, which shows a list of items, and when the user clicks on it, the id of that node is remembered. So when we again open a tree I want to bring that node into the visible area.

@Lodin
Copy link
Owner

Lodin commented Jul 24, 2021

Hi @bharatpatil. Sorry for making you wait for so long time.

Can we add a initialScrollToItem prop (which takes an id) in addition to scrollToItem method

Why cannot you use the useEffect (or componentDidMount) for doing it manually? The library is designed to be as small as possible, and everything that is not essential for the core functionality shouldn't be included.

@gregjoeval
Copy link

if you know the node id, this should work

  useEffect(
    () => {
      if (scrollToNodeId !== null) {
        ref.current?.scrollToItem(scrollToNodeId);
      }
    },
    // Note: only want this to run once
    // eslint-disable-next-line react-hooks/exhaustive-deps
    []
  );

I have a more complicated use case where the node id is not known and must be searched for, but unless other need it I'm not going to take the time right now to include it here

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

No branches or pull requests

3 participants