@@ -36,22 +36,22 @@ import mapKeyEventCallbacks from '../../../utilities/key-callbacks';
36
36
// ## Constants
37
37
import { TREE_BRANCH } from '../../../utilities/constants' ;
38
38
39
- const handleExpandClick = ( event , props ) => {
39
+ const handleExpand = ( event , props ) => {
40
40
EventUtil . trap ( event ) ;
41
41
42
- if ( isFunction ( props . onExpandClick ) ) {
43
- props . onExpandClick ( event , {
42
+ if ( isFunction ( props . onExpand ) ) {
43
+ props . onExpand ( event , {
44
44
node : props . node ,
45
45
expand : ! props . node . expanded ,
46
46
treeIndex : props . treeIndex ,
47
47
} ) ;
48
48
}
49
49
} ;
50
50
51
- const handleClick = ( event , props ) => {
51
+ const handleSelect = ( event , props ) => {
52
52
EventUtil . trap ( event ) ;
53
- if ( isFunction ( props . onClick ) ) {
54
- props . onClick ( event , {
53
+ if ( isFunction ( props . onSelect ) ) {
54
+ props . onSelect ( event , {
55
55
node : props . node ,
56
56
select : ! props . node . selected ,
57
57
treeIndex : props . treeIndex ,
@@ -91,7 +91,7 @@ const handleKeyDownDown = (event, props) => {
91
91
if ( props . focusedNodeIndex === props . treeIndex ) {
92
92
// Select the next visible node
93
93
const flattenedNode = findNextNode ( props . flattenedNodes , props . node ) ;
94
- props . onClick (
94
+ props . onSelect (
95
95
event ,
96
96
{
97
97
node : flattenedNode . node ,
@@ -107,7 +107,7 @@ const handleKeyDownUp = (event, props) => {
107
107
if ( props . focusedNodeIndex === props . treeIndex ) {
108
108
// Go to the previous visible node
109
109
const flattenedNode = findPreviousNode ( props . flattenedNodes , props . node ) ;
110
- props . onClick (
110
+ props . onSelect (
111
111
event ,
112
112
{
113
113
node : flattenedNode . node ,
@@ -125,25 +125,25 @@ const handleKeyDownRight = (event, props) => {
125
125
handleKeyDownDown ( event , props ) ;
126
126
}
127
127
} else {
128
- handleExpandClick ( event , props ) ;
128
+ handleExpand ( event , props ) ;
129
129
}
130
130
} ;
131
131
132
132
const handleKeyDownLeft = ( event , props ) => {
133
133
if ( props . node . expanded ) {
134
- handleExpandClick ( event , props ) ;
134
+ handleExpand ( event , props ) ;
135
135
} else {
136
136
const nodes = props . flattenedNodes . map (
137
137
( flattenedNode ) => flattenedNode . node
138
138
) ;
139
139
const index = nodes . indexOf ( props . parent ) ;
140
140
if ( index !== - 1 ) {
141
- props . onExpandClick ( event , {
141
+ props . onExpand ( event , {
142
142
node : props . parent ,
143
143
expand : ! props . parent . expanded ,
144
144
treeIndex : props . flattenedNodes [ index ] . treeIndex ,
145
145
} ) ;
146
- props . onClick (
146
+ props . onSelect (
147
147
event ,
148
148
{
149
149
node : props . parent ,
@@ -157,7 +157,7 @@ const handleKeyDownLeft = (event, props) => {
157
157
} ;
158
158
159
159
const handleKeyDownEnter = ( event , props ) => {
160
- handleClick ( event , props ) ;
160
+ handleSelect ( event , props ) ;
161
161
} ;
162
162
163
163
const handleKeyDown = ( event , props ) => {
@@ -174,7 +174,7 @@ const handleKeyDown = (event, props) => {
174
174
175
175
const handleFocus = ( event , props ) => {
176
176
if ( ! props . focusedNodeIndex ) {
177
- handleClick ( event , props ) ;
177
+ handleSelect ( event , props ) ;
178
178
}
179
179
} ;
180
180
@@ -304,7 +304,7 @@ const renderBranch = (children, props) => {
304
304
'slds-is-selected' : isSelected ,
305
305
} ) }
306
306
onClick = { ( event ) => {
307
- handleClick ( event , props ) ;
307
+ handleSelect ( event , props ) ;
308
308
} }
309
309
>
310
310
{ /* eslint-enable jsx-a11y/no-static-element-interactions */ }
@@ -318,7 +318,7 @@ const renderBranch = (children, props) => {
318
318
role = "presentation"
319
319
aria-controls = { props . htmlId }
320
320
onClick = { ( event ) => {
321
- handleExpandClick ( event , props ) ;
321
+ handleExpand ( event , props ) ;
322
322
} }
323
323
tabIndex = "-1"
324
324
/>
@@ -370,13 +370,13 @@ renderBranch.propTypes = {
370
370
*/
371
371
node : PropTypes . object . isRequired ,
372
372
/**
373
- * Function that will run whenever an item or branch is clicked.
373
+ * This function triggers when the expand or collapse icon is clicked or due to keyboard navigation .
374
374
*/
375
- onClick : PropTypes . func ,
375
+ onExpand : PropTypes . func . isRequired ,
376
376
/**
377
- * This function triggers when the expand or collapse icon is clicked.
377
+ * Function that will run whenever an item or branch is clicked.
378
378
*/
379
- onExpandClick : PropTypes . func . isRequired ,
379
+ onSelect : PropTypes . func ,
380
380
/**
381
381
* Highlights term if found in node label
382
382
*/
@@ -418,7 +418,7 @@ const Branch = (props) => {
418
418
let treeIndex = '' ;
419
419
let children ;
420
420
421
- const { treeId, level, onExpandClick , searchTerm } = props ;
421
+ const { treeId, level, onExpand , searchTerm } = props ;
422
422
423
423
if ( Array . isArray ( props . getNodes ( props . node ) ) ) {
424
424
children = props . node . nodes . map ( ( node , index ) => {
@@ -444,8 +444,8 @@ const Branch = (props) => {
444
444
treeHasFocus = { props . treeHasFocus }
445
445
onNodeBlur = { props . onNodeBlur }
446
446
nodes = { node . nodes }
447
- onClick = { props . onClick }
448
- onExpandClick = { onExpandClick }
447
+ onSelect = { props . onSelect }
448
+ onExpand = { onExpand }
449
449
searchTerm = { searchTerm }
450
450
treeId = { treeId }
451
451
treeIndex = { treeIndex }
@@ -465,8 +465,8 @@ const Branch = (props) => {
465
465
focusedNodeIndex = { props . focusedNodeIndex }
466
466
treeHasFocus = { props . treeHasFocus }
467
467
onNodeBlur = { props . onNodeBlur }
468
- onClick = { props . onClick }
469
- onExpandClick = { onExpandClick }
468
+ onSelect = { props . onSelect }
469
+ onExpand = { onExpand }
470
470
searchTerm = { searchTerm }
471
471
treeIndex = { treeIndex }
472
472
treeId = { treeId }
@@ -529,13 +529,13 @@ Branch.propTypes = {
529
529
*/
530
530
node : PropTypes . object . isRequired ,
531
531
/**
532
- * Function that will run whenever an item or branch is clicked .
532
+ * Function that will run whenever an item or branch is selected (click or keyboard) .
533
533
*/
534
- onClick : PropTypes . func ,
534
+ onSelect : PropTypes . func ,
535
535
/**
536
536
* This function triggers when the expand or collapse icon is clicked.
537
537
*/
538
- onExpandClick : PropTypes . func . isRequired ,
538
+ onExpand : PropTypes . func . isRequired ,
539
539
/**
540
540
* Highlights term if found in node label
541
541
*/
0 commit comments