Skip to content

Commit db2ada4

Browse files
authored
fix: Keep search tree intact upon selection 🐛 (#194)
* fix: Keep search tree intact upon selection Closes #190 * chore: Updated bundle
1 parent 24edcd5 commit db2ada4

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

docs/bundle.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ class DropdownTreeSelect extends Component {
129129

130130
onNodeToggle = id => {
131131
this.treeManager.toggleNodeExpandState(id)
132-
this.setState({ tree: this.treeManager.tree })
132+
const tree = this.state.searchModeOn ? this.treeManager.matchTree : this.treeManager.tree
133+
this.setState({ tree })
133134
typeof this.props.onNodeToggle === 'function' && this.props.onNodeToggle(this.treeManager.getNodeById(id))
134135
}
135136

@@ -143,8 +144,9 @@ class DropdownTreeSelect extends Component {
143144
tags = this.treeManager.getTags()
144145
}
145146

147+
const tree = this.state.searchModeOn ? this.treeManager.matchTree : this.treeManager.tree
146148
const nextState = {
147-
tree: this.treeManager.tree,
149+
tree,
148150
tags,
149151
showDropdown
150152
}

src/tree-manager/index.js

+5
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ class TreeManager {
8080
})
8181

8282
const allNodesHidden = matches.length === 0
83+
84+
// we store a local reference so that components can use it in subsequent renders
85+
// this is the least intrusive way of fixing #190
86+
this.matchTree = matchTree
87+
8388
return { allNodesHidden, tree: matchTree }
8489
}
8590

0 commit comments

Comments
 (0)