File tree Expand file tree Collapse file tree 2 files changed +22
-3
lines changed Expand file tree Collapse file tree 2 files changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -185,14 +185,17 @@ export default class Tree extends React.Component {
185185 * @return {void }
186186 */
187187 handleNodeToggle ( nodeId ) {
188+ const data = clone ( this . state . data ) ;
189+ const matches = this . findNodesById ( nodeId , data , [ ] ) ;
190+ const targetNode = matches [ 0 ] ;
191+
188192 if ( this . props . collapsible ) {
189- const data = clone ( this . state . data ) ;
190- const matches = this . findNodesById ( nodeId , data , [ ] ) ;
191- const targetNode = matches [ 0 ] ;
192193 targetNode . _collapsed
193194 ? this . expandNode ( targetNode )
194195 : this . collapseNode ( targetNode ) ;
195196 this . setState ( { data } , ( ) => this . handleOnClickCb ( targetNode ) ) ;
197+ } else {
198+ this . handleOnClickCb ( targetNode ) ;
196199 }
197200 }
198201
Original file line number Diff line number Diff line change @@ -211,6 +211,22 @@ describe('<Tree />', () => {
211211 } ) ;
212212
213213
214+ it ( 'calls the onClick callback when `props.collapsible` is false' , ( ) => {
215+ const onClickSpy = jest . fn ( ) ;
216+ const renderedComponent = mount (
217+ < Tree
218+ data = { mockData }
219+ collapsible = { false }
220+ onClick = { onClickSpy }
221+ />
222+ ) ;
223+
224+ renderedComponent . find ( Node ) . first ( ) . simulate ( 'click' ) ;
225+
226+ expect ( onClickSpy ) . toHaveBeenCalledTimes ( 1 ) ;
227+ } ) ;
228+
229+
214230 it ( 'clones the clicked node\'s data & passes it to the onClick callback if defined' , ( ) => {
215231 const onClickSpy = jest . fn ( ) ;
216232 const renderedComponent = mount (
You can’t perform that action at this time.
0 commit comments