11import classNames from 'classnames' ;
2- import toArray from 'rc-util/lib/Children/toArray' ;
32import useMergedState from 'rc-util/lib/hooks/useMergedState' ;
4- import warning from 'rc-util/lib/warning' ;
53import React from 'react' ;
6- import type { CollapsePanelProps , CollapseProps , CollapsibleType , ItemType } from './interface' ;
4+ import type { CollapseProps , ItemType } from './interface' ;
75import CollapsePanel from './Panel' ;
86
97function getActiveKeysArray ( activeKey : React . Key | React . Key [ ] ) {
@@ -23,7 +21,6 @@ const Collapse = React.forwardRef<HTMLDivElement, CollapseProps>((props, ref) =>
2321 style,
2422 accordion,
2523 className,
26- children : rawChildren ,
2724 collapsible,
2825 openMotion,
2926 expandIcon,
@@ -58,68 +55,6 @@ const Collapse = React.forwardRef<HTMLDivElement, CollapseProps>((props, ref) =>
5855 } ) ;
5956
6057 // ======================== 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- } ;
12358
12459 // eslint-disable-next-line @typescript-eslint/no-shadow
12560 const convertItemsToNodes = ( items : ItemType [ ] ) =>
@@ -172,10 +107,6 @@ const Collapse = React.forwardRef<HTMLDivElement, CollapseProps>((props, ref) =>
172107 ) ;
173108 } ) ;
174109
175- const children = Array . isArray ( items )
176- ? [ convertItemsToNodes ( items ) , rawChildren ]
177- : toArray ( rawChildren ) . map ( getNewChild ) ;
178-
179110 // ======================== Render ========================
180111 return (
181112 < div
@@ -184,14 +115,10 @@ const Collapse = React.forwardRef<HTMLDivElement, CollapseProps>((props, ref) =>
184115 style = { style }
185116 role = { accordion ? 'tablist' : undefined }
186117 >
187- { children }
118+ { convertItemsToNodes ( items ) }
119+ { props . children }
188120 </ div >
189121 ) ;
190122} ) ;
191123
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