@@ -7,7 +7,7 @@ type Props = Pick<
77 CollapsePanelProps ,
88 'prefixCls' | 'onItemClick' | 'openMotion' | 'expandIcon' | 'classNames' | 'styles'
99> &
10- Pick < CollapseProps , 'accordion' | 'collapsible' | 'destroyInactivePanel ' > & {
10+ Pick < CollapseProps , 'accordion' | 'collapsible' | 'destroyOnHidden ' > & {
1111 activeKey : React . Key [ ] ;
1212 } ;
1313
@@ -16,7 +16,7 @@ const convertItemsToNodes = (items: ItemType[], props: Props) => {
1616 prefixCls,
1717 accordion,
1818 collapsible,
19- destroyInactivePanel ,
19+ destroyOnHidden ,
2020 onItemClick,
2121 activeKey,
2222 openMotion,
@@ -32,18 +32,20 @@ const convertItemsToNodes = (items: ItemType[], props: Props) => {
3232 key : rawKey ,
3333 collapsible : rawCollapsible ,
3434 onItemClick : rawOnItemClick ,
35- destroyInactivePanel : rawDestroyInactivePanel ,
35+ destroyOnHidden : rawDestroyOnHidden ,
3636 ...restProps
3737 } = item ;
3838
3939 // You may be puzzled why you want to convert them all into strings, me too.
4040 // Maybe: https://github.com/react-component/collapse/blob/aac303a8b6ff30e35060b4f8fecde6f4556fcbe2/src/Collapse.tsx#L15
4141 const key = String ( rawKey ?? index ) ;
4242 const mergeCollapsible = rawCollapsible ?? collapsible ;
43- const mergeDestroyInactivePanel = rawDestroyInactivePanel ?? destroyInactivePanel ;
43+ const mergedDestroyOnHidden = rawDestroyOnHidden ?? destroyOnHidden ;
4444
4545 const handleItemClick = ( value : React . Key ) => {
46- if ( mergeCollapsible === 'disabled' ) return ;
46+ if ( mergeCollapsible === 'disabled' ) {
47+ return ;
48+ }
4749 onItemClick ( value ) ;
4850 rawOnItemClick ?.( value ) ;
4951 } ;
@@ -70,7 +72,7 @@ const convertItemsToNodes = (items: ItemType[], props: Props) => {
7072 header = { label }
7173 collapsible = { mergeCollapsible }
7274 onItemClick = { handleItemClick }
73- destroyInactivePanel = { mergeDestroyInactivePanel }
75+ destroyOnHidden = { mergedDestroyOnHidden }
7476 >
7577 { children }
7678 </ CollapsePanel >
@@ -86,13 +88,15 @@ const getNewChild = (
8688 index : number ,
8789 props : Props ,
8890) => {
89- if ( ! child ) return null ;
91+ if ( ! child ) {
92+ return null ;
93+ }
9094
9195 const {
9296 prefixCls,
9397 accordion,
9498 collapsible,
95- destroyInactivePanel ,
99+ destroyOnHidden ,
96100 onItemClick,
97101 activeKey,
98102 openMotion,
@@ -106,7 +110,7 @@ const getNewChild = (
106110 const {
107111 header,
108112 headerClass,
109- destroyInactivePanel : childDestroyInactivePanel ,
113+ destroyOnHidden : childDestroyOnHidden ,
110114 collapsible : childCollapsible ,
111115 onItemClick : childOnItemClick ,
112116 } = child . props ;
@@ -121,7 +125,9 @@ const getNewChild = (
121125 const mergeCollapsible = childCollapsible ?? collapsible ;
122126
123127 const handleItemClick = ( value : React . Key ) => {
124- if ( mergeCollapsible === 'disabled' ) return ;
128+ if ( mergeCollapsible === 'disabled' ) {
129+ return ;
130+ }
125131 onItemClick ( value ) ;
126132 childOnItemClick ?.( value ) ;
127133 } ;
@@ -135,7 +141,7 @@ const getNewChild = (
135141 styles,
136142 isActive,
137143 prefixCls,
138- destroyInactivePanel : childDestroyInactivePanel ?? destroyInactivePanel ,
144+ destroyOnHidden : childDestroyOnHidden ?? destroyOnHidden ,
139145 openMotion,
140146 accordion,
141147 children : child . props . children ,
@@ -155,7 +161,7 @@ const getNewChild = (
155161 }
156162 } ) ;
157163
158- return React . cloneElement ( child , childProps ) ;
164+ return React . cloneElement < CollapsePanelProps > ( child , childProps ) ;
159165} ;
160166
161167function useItems (
@@ -166,8 +172,9 @@ function useItems(
166172 if ( Array . isArray ( items ) ) {
167173 return convertItemsToNodes ( items , props ) ;
168174 }
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+ ) ;
171178}
172179
173180export default useItems ;
0 commit comments