1
1
import classNames from 'classnames' ;
2
- import toArray from 'rc-util/lib/Children/toArray' ;
3
2
import useMergedState from 'rc-util/lib/hooks/useMergedState' ;
4
- import warning from 'rc-util/lib/warning' ;
5
3
import React from 'react' ;
6
- import type { CollapsePanelProps , CollapseProps , CollapsibleType , ItemType } from './interface' ;
4
+ import type { CollapseProps , ItemType } from './interface' ;
7
5
import CollapsePanel from './Panel' ;
8
6
9
7
function getActiveKeysArray ( activeKey : React . Key | React . Key [ ] ) {
@@ -23,7 +21,6 @@ const Collapse = React.forwardRef<HTMLDivElement, CollapseProps>((props, ref) =>
23
21
style,
24
22
accordion,
25
23
className,
26
- children : rawChildren ,
27
24
collapsible,
28
25
openMotion,
29
26
expandIcon,
@@ -58,68 +55,6 @@ const Collapse = React.forwardRef<HTMLDivElement, CollapseProps>((props, ref) =>
58
55
} ) ;
59
56
60
57
// ======================== Children ========================
61
- warning (
62
- ! rawChildren ,
63
- '`children` will be removed in next major version. Please use `items` instead.' ,
64
- ) ;
65
-
66
- const getNewChild = ( child : React . ReactElement < CollapsePanelProps > , index : number ) => {
67
- if ( ! child ) return null ;
68
-
69
- const key = child . key || String ( index ) ;
70
-
71
- const {
72
- header,
73
- headerClass,
74
- destroyInactivePanel : childDestroyInactivePanel ,
75
- collapsible : childCollapsible ,
76
- onItemClick : childOnItemClick ,
77
- } = child . props ;
78
-
79
- let isActive = false ;
80
- if ( accordion ) {
81
- isActive = activeKey [ 0 ] === key ;
82
- } else {
83
- isActive = activeKey . indexOf ( key ) > - 1 ;
84
- }
85
-
86
- const mergeCollapsible : CollapsibleType = childCollapsible ?? collapsible ;
87
-
88
- const handleItemClick = ( value : React . Key ) => {
89
- if ( mergeCollapsible === 'disabled' ) return ;
90
- onClickItem ( value ) ;
91
- childOnItemClick ?.( value ) ;
92
- } ;
93
-
94
- const childProps = {
95
- key,
96
- panelKey : key ,
97
- header,
98
- headerClass,
99
- isActive,
100
- prefixCls,
101
- destroyInactivePanel : childDestroyInactivePanel ?? destroyInactivePanel ,
102
- openMotion,
103
- accordion,
104
- children : child . props . children ,
105
- onItemClick : handleItemClick ,
106
- expandIcon,
107
- collapsible : mergeCollapsible ,
108
- } ;
109
-
110
- // https://github.com/ant-design/ant-design/issues/20479
111
- if ( typeof child . type === 'string' ) {
112
- return child ;
113
- }
114
-
115
- Object . keys ( childProps ) . forEach ( ( propName ) => {
116
- if ( typeof childProps [ propName ] === 'undefined' ) {
117
- delete childProps [ propName ] ;
118
- }
119
- } ) ;
120
-
121
- return React . cloneElement ( child , childProps ) ;
122
- } ;
123
58
124
59
// eslint-disable-next-line @typescript-eslint/no-shadow
125
60
const convertItemsToNodes = ( items : ItemType [ ] ) =>
@@ -172,10 +107,6 @@ const Collapse = React.forwardRef<HTMLDivElement, CollapseProps>((props, ref) =>
172
107
) ;
173
108
} ) ;
174
109
175
- const children = Array . isArray ( items )
176
- ? [ convertItemsToNodes ( items ) , rawChildren ]
177
- : toArray ( rawChildren ) . map ( getNewChild ) ;
178
-
179
110
// ======================== Render ========================
180
111
return (
181
112
< div
@@ -184,14 +115,10 @@ const Collapse = React.forwardRef<HTMLDivElement, CollapseProps>((props, ref) =>
184
115
style = { style }
185
116
role = { accordion ? 'tablist' : undefined }
186
117
>
187
- { children }
118
+ { convertItemsToNodes ( items ) }
119
+ { props . children }
188
120
</ div >
189
121
) ;
190
122
} ) ;
191
123
192
- export default Object . assign ( Collapse , {
193
- /**
194
- * @deprecated use `items` instead, will be removed in `v4.0.0`
195
- */
196
- Panel : CollapsePanel ,
197
- } ) ;
124
+ export default Collapse ;
0 commit comments