@@ -7,7 +7,7 @@ type Props = Pick<
7
7
CollapsePanelProps ,
8
8
'prefixCls' | 'onItemClick' | 'openMotion' | 'expandIcon' | 'classNames' | 'styles'
9
9
> &
10
- Pick < CollapseProps , 'accordion' | 'collapsible' | 'destroyInactivePanel ' > & {
10
+ Pick < CollapseProps , 'accordion' | 'collapsible' | 'destroyOnHidden ' > & {
11
11
activeKey : React . Key [ ] ;
12
12
} ;
13
13
@@ -16,7 +16,7 @@ const convertItemsToNodes = (items: ItemType[], props: Props) => {
16
16
prefixCls,
17
17
accordion,
18
18
collapsible,
19
- destroyInactivePanel ,
19
+ destroyOnHidden ,
20
20
onItemClick,
21
21
activeKey,
22
22
openMotion,
@@ -32,18 +32,20 @@ const convertItemsToNodes = (items: ItemType[], props: Props) => {
32
32
key : rawKey ,
33
33
collapsible : rawCollapsible ,
34
34
onItemClick : rawOnItemClick ,
35
- destroyInactivePanel : rawDestroyInactivePanel ,
35
+ destroyOnHidden : rawDestroyOnHidden ,
36
36
...restProps
37
37
} = item ;
38
38
39
39
// You may be puzzled why you want to convert them all into strings, me too.
40
40
// Maybe: https://github.com/react-component/collapse/blob/aac303a8b6ff30e35060b4f8fecde6f4556fcbe2/src/Collapse.tsx#L15
41
41
const key = String ( rawKey ?? index ) ;
42
42
const mergeCollapsible = rawCollapsible ?? collapsible ;
43
- const mergeDestroyInactivePanel = rawDestroyInactivePanel ?? destroyInactivePanel ;
43
+ const mergedDestroyOnHidden = rawDestroyOnHidden ?? destroyOnHidden ;
44
44
45
45
const handleItemClick = ( value : React . Key ) => {
46
- if ( mergeCollapsible === 'disabled' ) return ;
46
+ if ( mergeCollapsible === 'disabled' ) {
47
+ return ;
48
+ }
47
49
onItemClick ( value ) ;
48
50
rawOnItemClick ?.( value ) ;
49
51
} ;
@@ -70,7 +72,7 @@ const convertItemsToNodes = (items: ItemType[], props: Props) => {
70
72
header = { label }
71
73
collapsible = { mergeCollapsible }
72
74
onItemClick = { handleItemClick }
73
- destroyInactivePanel = { mergeDestroyInactivePanel }
75
+ destroyOnHidden = { mergedDestroyOnHidden }
74
76
>
75
77
{ children }
76
78
</ CollapsePanel >
@@ -86,13 +88,15 @@ const getNewChild = (
86
88
index : number ,
87
89
props : Props ,
88
90
) => {
89
- if ( ! child ) return null ;
91
+ if ( ! child ) {
92
+ return null ;
93
+ }
90
94
91
95
const {
92
96
prefixCls,
93
97
accordion,
94
98
collapsible,
95
- destroyInactivePanel ,
99
+ destroyOnHidden ,
96
100
onItemClick,
97
101
activeKey,
98
102
openMotion,
@@ -106,7 +110,7 @@ const getNewChild = (
106
110
const {
107
111
header,
108
112
headerClass,
109
- destroyInactivePanel : childDestroyInactivePanel ,
113
+ destroyOnHidden : childDestroyOnHidden ,
110
114
collapsible : childCollapsible ,
111
115
onItemClick : childOnItemClick ,
112
116
} = child . props ;
@@ -121,7 +125,9 @@ const getNewChild = (
121
125
const mergeCollapsible = childCollapsible ?? collapsible ;
122
126
123
127
const handleItemClick = ( value : React . Key ) => {
124
- if ( mergeCollapsible === 'disabled' ) return ;
128
+ if ( mergeCollapsible === 'disabled' ) {
129
+ return ;
130
+ }
125
131
onItemClick ( value ) ;
126
132
childOnItemClick ?.( value ) ;
127
133
} ;
@@ -135,7 +141,7 @@ const getNewChild = (
135
141
styles,
136
142
isActive,
137
143
prefixCls,
138
- destroyInactivePanel : childDestroyInactivePanel ?? destroyInactivePanel ,
144
+ destroyOnHidden : childDestroyOnHidden ?? destroyOnHidden ,
139
145
openMotion,
140
146
accordion,
141
147
children : child . props . children ,
@@ -155,7 +161,7 @@ const getNewChild = (
155
161
}
156
162
} ) ;
157
163
158
- return React . cloneElement ( child , childProps ) ;
164
+ return React . cloneElement < CollapsePanelProps > ( child , childProps ) ;
159
165
} ;
160
166
161
167
function useItems (
@@ -166,8 +172,9 @@ function useItems(
166
172
if ( Array . isArray ( items ) ) {
167
173
return convertItemsToNodes ( items , props ) ;
168
174
}
169
-
170
- return toArray ( rawChildren ) . map ( ( child , index ) => getNewChild ( child , index , props ) ) ;
175
+ return toArray ( rawChildren ) . map ( ( child , index ) =>
176
+ getNewChild ( child as React . ReactElement < CollapsePanelProps > , index , props ) ,
177
+ ) ;
171
178
}
172
179
173
180
export default useItems ;
0 commit comments