@@ -4,7 +4,7 @@ import classNames from 'classnames';
4
4
import shallowEqual from 'shallowequal' ;
5
5
import toArray from 'rc-util/lib/Children/toArray' ;
6
6
import CollapsePanel from './Panel' ;
7
- import { CollapseProps , CollapsibleType } from './interface' ;
7
+ import type { CollapseProps , CollapsibleType } from './interface' ;
8
8
9
9
function getActiveKeysArray ( activeKey : React . Key | React . Key [ ] ) {
10
10
let currentActiveKey = activeKey ;
@@ -78,18 +78,30 @@ class Collapse extends React.Component<CollapseProps, CollapseState> {
78
78
if ( ! child ) return null ;
79
79
80
80
const { activeKey } = this . state ;
81
- const { prefixCls, openMotion, accordion, destroyInactivePanel : rootDestroyInactivePanel , expandIcon, collapsible } = this . props ;
81
+ const {
82
+ prefixCls,
83
+ openMotion,
84
+ accordion,
85
+ destroyInactivePanel : rootDestroyInactivePanel ,
86
+ expandIcon,
87
+ collapsible,
88
+ } = this . props ;
82
89
// If there is no key provide, use the panel order as default key
83
90
const key = child . key || String ( index ) ;
84
- const { header, headerClass, destroyInactivePanel, collapsible : childCollapsible } = child . props ;
91
+ const {
92
+ header,
93
+ headerClass,
94
+ destroyInactivePanel,
95
+ collapsible : childCollapsible ,
96
+ } = child . props ;
85
97
let isActive = false ;
86
98
if ( accordion ) {
87
99
isActive = activeKey [ 0 ] === key ;
88
100
} else {
89
101
isActive = activeKey . indexOf ( key ) > - 1 ;
90
102
}
91
103
92
- const mergeCollapsible : CollapsibleType = childCollapsible ?? collapsible ;
104
+ const mergeCollapsible : CollapsibleType = childCollapsible ?? collapsible ;
93
105
94
106
const props = {
95
107
key,
@@ -112,6 +124,12 @@ class Collapse extends React.Component<CollapseProps, CollapseState> {
112
124
return child ;
113
125
}
114
126
127
+ Object . keys ( props ) . forEach ( ( propName : keyof typeof props ) => {
128
+ if ( typeof props [ propName ] === 'undefined' ) {
129
+ delete props [ propName ] ;
130
+ }
131
+ } ) ;
132
+
115
133
return React . cloneElement ( child , props ) ;
116
134
} ;
117
135
0 commit comments