Skip to content

Commit 5d57c9a

Browse files
committed
Use the node key so outlines move around properly when unique keys are set
1 parent 8568925 commit 5d57c9a

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-sortable-tree",
3-
"version": "0.0.8",
3+
"version": "0.0.9",
44
"description": "Drag-and-drop sortable representation of hierarchical data",
55
"scripts": {
66
"build": "npm run lint && npm run test && npm run build:demo && npm run build:umd",

src/react-sortable-tree.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,8 @@ class ReactSortableTree extends Component {
286286
} = this.state;
287287

288288
// Get indices for rows that match the search conditions
289-
const matchIndices = {};
290-
searchMatches.forEach(({ treeIndex: tIndex }, i) => { matchIndices[tIndex] = i; });
289+
const matchKeys = {};
290+
searchMatches.forEach(({ path }, i) => { matchKeys[path[path.length - 1]] = i; });
291291

292292
// Seek to the focused search result if there is one specified
293293
const scrollToInfo = searchFocusTreeIndex !== null ? { scrollToIndex: searchFocusTreeIndex } : {};
@@ -315,7 +315,7 @@ class ReactSortableTree extends Component {
315315
key,
316316
rowStyle,
317317
() => (rows[index - 1] || null),
318-
matchIndices
318+
matchKeys
319319
)}
320320
/>
321321
)}
@@ -324,11 +324,12 @@ class ReactSortableTree extends Component {
324324
);
325325
}
326326

327-
renderRow({ node, path, lowerSiblingCounts, treeIndex }, listIndex, key, style, getPrevRow, matchIndices) {
327+
renderRow({ node, path, lowerSiblingCounts, treeIndex }, listIndex, key, style, getPrevRow, matchKeys) {
328328
const NodeContentRenderer = this.nodeContentRenderer;
329-
const isSearchMatch = treeIndex in matchIndices;
329+
const nodeKey = path[path.length - 1];
330+
const isSearchMatch = nodeKey in matchKeys;
330331
const isSearchFocus = isSearchMatch &&
331-
matchIndices[treeIndex] === this.props.searchFocusOffset;
332+
matchKeys[nodeKey] === this.props.searchFocusOffset;
332333

333334
const nodeProps = !this.props.generateNodeProps ? {} : this.props.generateNodeProps({
334335
node,

0 commit comments

Comments
 (0)