1
1
import classNames from 'classnames' ;
2
- import CSSMotion from 'rc-motion' ;
3
2
import KeyCode from '@rc-component/util/lib/KeyCode' ;
4
- import React , { useMemo } from 'react' ;
3
+ import React from 'react' ;
5
4
import type { CollapsePanelProps } from './interface' ;
6
5
import PanelContent from './PanelContent' ;
7
6
@@ -23,7 +22,7 @@ const CollapsePanel = React.forwardRef<HTMLDetailsElement, CollapsePanelProps>((
23
22
header,
24
23
expandIcon,
25
24
openMotion,
26
- destroyInactivePanel ,
25
+ destroyOnHidden ,
27
26
children,
28
27
...resetProps
29
28
} = props ;
@@ -32,15 +31,6 @@ const CollapsePanel = React.forwardRef<HTMLDetailsElement, CollapsePanelProps>((
32
31
33
32
const ifExtraExist = extra !== null && extra !== undefined && typeof extra !== 'boolean' ;
34
33
35
- // ? 用于判断浏览器是否支持::details-content 否则使用CSSMotion
36
- const supportsDetailsContentSelector = useMemo (
37
- ( ) =>
38
- typeof document !== 'undefined' && typeof document . createElement === 'function'
39
- ? CSS . supports ( 'selector(details::details-content)' )
40
- : false ,
41
- [ ] ,
42
- ) ;
43
-
44
34
const collapsibleProps = {
45
35
onClick : ( e : React . MouseEvent ) => {
46
36
onItemClick ?.( panelKey ) ;
@@ -78,7 +68,7 @@ const CollapsePanel = React.forwardRef<HTMLDetailsElement, CollapsePanelProps>((
78
68
} ,
79
69
className ,
80
70
// ? 修改为details实现后动画是作用在details元素上 需要将motionName设置在details上
81
- supportsDetailsContentSelector && openMotion ?. motionName ,
71
+ openMotion ?. motionName ,
82
72
) ;
83
73
84
74
const headerClassName = classNames (
@@ -98,68 +88,6 @@ const CollapsePanel = React.forwardRef<HTMLDetailsElement, CollapsePanelProps>((
98
88
} ;
99
89
100
90
// ======================== Render ========================
101
-
102
- const leavedClassName = `${ prefixCls } -panel-hidden` ;
103
- const createPanelContent = (
104
- props : Partial < {
105
- className : string ;
106
- style : React . CSSProperties ;
107
- motionRef : ( node : HTMLDivElement ) => void ;
108
- } > ,
109
- ) => {
110
- const { className, style, motionRef } = props ;
111
-
112
- return (
113
- < PanelContent
114
- ref = { motionRef }
115
- prefixCls = { prefixCls }
116
- className = { className }
117
- classNames = { customizeClassNames }
118
- style = { style }
119
- styles = { styles }
120
- isActive = { isActive }
121
- forceRender = { forceRender }
122
- role = { accordion ? 'tabpanel' : void 0 }
123
- >
124
- { children }
125
- </ PanelContent >
126
- ) ;
127
- } ;
128
- let detailsChildren = (
129
- < CSSMotion
130
- visible = { isActive }
131
- leavedClassName = { leavedClassName }
132
- { ...openMotion }
133
- forceRender = { forceRender }
134
- removeOnLeave = { destroyInactivePanel }
135
- >
136
- { ( { className, style } , motionRef ) =>
137
- createPanelContent ( {
138
- className,
139
- style,
140
- motionRef,
141
- } )
142
- }
143
- </ CSSMotion >
144
- ) ;
145
-
146
- // ? 模拟CSSMotion子元素生命周期管理
147
- if ( supportsDetailsContentSelector ) {
148
- if ( isActive ) {
149
- detailsChildren = createPanelContent ( { } ) ;
150
- } else if ( ! destroyInactivePanel && leavedClassName ) {
151
- detailsChildren = createPanelContent ( {
152
- className : leavedClassName ,
153
- } ) ;
154
- } else if ( forceRender || ( ! destroyInactivePanel && ! leavedClassName ) ) {
155
- detailsChildren = createPanelContent ( {
156
- style : { display : 'none' } ,
157
- } ) ;
158
- } else {
159
- detailsChildren = null ;
160
- }
161
- }
162
-
163
91
return (
164
92
< details { ...resetProps } ref = { ref } className = { collapsePanelClassNames } open = { isActive } >
165
93
< summary { ...headerProps } >
@@ -173,7 +101,16 @@ const CollapsePanel = React.forwardRef<HTMLDetailsElement, CollapsePanelProps>((
173
101
</ span >
174
102
{ ifExtraExist && < div className = { `${ prefixCls } -extra` } > { extra } </ div > }
175
103
</ summary >
176
- { detailsChildren }
104
+ < PanelContent
105
+ prefixCls = { prefixCls }
106
+ classNames = { customizeClassNames }
107
+ styles = { styles }
108
+ isActive = { isActive }
109
+ forceRender = { forceRender }
110
+ role = { accordion ? 'tabpanel' : undefined }
111
+ >
112
+ { children }
113
+ </ PanelContent >
177
114
</ details >
178
115
) ;
179
116
} ) ;
0 commit comments