@@ -2,7 +2,7 @@ import classNames from 'classnames';
2
2
import toArray from 'rc-util/lib/Children/toArray' ;
3
3
import useMergedState from 'rc-util/lib/hooks/useMergedState' ;
4
4
import React from 'react' ;
5
- import type { CollapseProps , CollapsibleType } from './interface' ;
5
+ import type { CollapsePanelProps , CollapseProps , CollapsibleType } from './interface' ;
6
6
import CollapsePanel from './Panel' ;
7
7
8
8
function getActiveKeysArray ( activeKey : React . Key | React . Key [ ] ) {
@@ -56,7 +56,7 @@ const Collapse = React.forwardRef<HTMLDivElement, CollapseProps>((props, ref) =>
56
56
} ) ;
57
57
58
58
// ======================== Children ========================
59
- const getNewChild = ( child : React . ReactElement , index : number ) => {
59
+ const getNewChild = ( child : React . ReactElement < CollapsePanelProps > , index : number ) => {
60
60
if ( ! child ) return null ;
61
61
62
62
const key = child . key || String ( index ) ;
@@ -66,6 +66,7 @@ const Collapse = React.forwardRef<HTMLDivElement, CollapseProps>((props, ref) =>
66
66
headerClass,
67
67
destroyInactivePanel : childDestroyInactivePanel ,
68
68
collapsible : childCollapsible ,
69
+ onItemClick : childOnItemClick ,
69
70
} = child . props ;
70
71
71
72
let isActive = false ;
@@ -77,6 +78,12 @@ const Collapse = React.forwardRef<HTMLDivElement, CollapseProps>((props, ref) =>
77
78
78
79
const mergeCollapsible : CollapsibleType = childCollapsible ?? collapsible ;
79
80
81
+ const handleItemClick = ( value : React . Key ) => {
82
+ if ( mergeCollapsible === 'disabled' ) return ;
83
+ onClickItem ( value ) ;
84
+ childOnItemClick ?.( value ) ;
85
+ } ;
86
+
80
87
const childProps = {
81
88
key,
82
89
panelKey : key ,
@@ -88,7 +95,7 @@ const Collapse = React.forwardRef<HTMLDivElement, CollapseProps>((props, ref) =>
88
95
openMotion,
89
96
accordion,
90
97
children : child . props . children ,
91
- onItemClick : mergeCollapsible === 'disabled' ? null : onClickItem ,
98
+ onItemClick : handleItemClick ,
92
99
expandIcon,
93
100
collapsible : mergeCollapsible ,
94
101
} ;
0 commit comments