frontend-collective / frontend-collective/react-sortable-tree

Scrolling to matched node doesn't work when treeData changed

Open
#305 0 comments 6 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
5k
Forks
914
PR merge metrics
No merged PRs in 30d

Description

I'm using the searchQuery and searchFocusOffset props to highlight a specific node in my list and scroll to it. This mostly works as intended, however, every time the actual `treeData` changes, the scrolling doesn't work.
See this example with a list and two buttons. Clicking one button adds an element to `treeData` - the scrolling to the highlighted node doesn't work. Clicking the other button causes a rerender of the list without changing `treeData` - the scrolling to the highlighted node works:
https://codesandbox.io/s/74mxjrlvjx
(Edit March, 4th 2021: The above link seems to have broken. I tried to replicate it here: https://codesandbox.io/s/sad-dream-g6x1n)

I've identified line 146 in react-sortable-tree.js as the cause of this issue. When `treeData` changes, `this.search(nextProps, false, false)` is called. Notice the `seekIndex` parameter is set to false - so no scrolling. Is this a bug or is there a reason why `seekIndex` is set to false in this case?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.