Skip to content
This repository has been archived by the owner on Sep 19, 2024. It is now read-only.

Is there a simple example code available that automatically scrolls to the treeIndex of the currently selected state? #72

Open
PlumpMath opened this issue Mar 6, 2024 · 1 comment

Comments

@PlumpMath
Copy link

PlumpMath commented Mar 6, 2024

Hello
version: "@nosferatu500/react-sortable-tree": "^4.4.0",
In the old method using reactVirtualizedListProps, automatic scrolling was enabled by simply referencing the treeIndex from the current state node.
With updates, the feature that once worked in a very old past version was abandoned for several years. Now, as the project I'm working on has successfully transitioned to the latest version of that module, I'm attempting to implement the auto-scroll feature again.

The following link is an example of navigating to that state.
https://virtuoso.dev/scroll-to-index

I would like to see an example of auto-scrolling to the current state in a sortable-tree, created with JavaScript instead of TypeScript.

There's a similar example in the code,

  const isScrollingVirtuoso = (scrollingState: any) => {
    if (virtuosoRef?.current) {
      virtuosoRef?.current.getState(virtuosoState => {
        setIsScrolling(scrollingState);
        setScrollTop(virtuosoState.scrollTop);
      })
    }
  }

&

virtuosoRef={virtuosoRef}
virtuosoProps={{ isScrolling: isScrollingVirtuoso }}

but it seems a bit odd to insert and search with current.getState as an argument in the isScrolling part, and it appears quite different from the virtuoso section.
If the decision is made based on the value returned by current.getState, is there no way to simply place an object containing a determined treeIndex value directly into the isScrolling position?

Another thing I'm curious about is whether, by default, there is a set state information that gets automatically configured without having to set up the virtuosoRef part using useRef or createRef. I wonder if it's possible to reference virtuosoRef in that default set state. Do I always have to create a new useRef or createRef to set the scroll?

Thanks.

@PlumpMath
Copy link
Author

I've succeeded in calling it with current.scrollToIndex({index: n .... }). It turns out the example code in the Virtuoso documentation is correct. However, the problem is that when I select the item at the bottom, the scroll goes up, and calling the scrollToIndex function does not seem to scroll to the location of the specified item. It seems like scrollToIndex is being executed, but I'm not sure why it's not working visually.

I'm currently waiting for the development of react-sortable-tree 5.x ?.

Thanks.

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

No branches or pull requests

1 participant