11import classNames from 'classnames' ;
2- import CSSMotion from 'rc-motion' ;
32import KeyCode from '@rc-component/util/lib/KeyCode' ;
4- import React , { useMemo } from 'react' ;
3+ import React from 'react' ;
54import type { CollapsePanelProps } from './interface' ;
65import PanelContent from './PanelContent' ;
76
@@ -23,7 +22,7 @@ const CollapsePanel = React.forwardRef<HTMLDetailsElement, CollapsePanelProps>((
2322 header,
2423 expandIcon,
2524 openMotion,
26- destroyInactivePanel ,
25+ destroyOnHidden ,
2726 children,
2827 ...resetProps
2928 } = props ;
@@ -32,15 +31,6 @@ const CollapsePanel = React.forwardRef<HTMLDetailsElement, CollapsePanelProps>((
3231
3332 const ifExtraExist = extra !== null && extra !== undefined && typeof extra !== 'boolean' ;
3433
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-
4434 const collapsibleProps = {
4535 onClick : ( e : React . MouseEvent ) => {
4636 onItemClick ?.( panelKey ) ;
@@ -78,7 +68,7 @@ const CollapsePanel = React.forwardRef<HTMLDetailsElement, CollapsePanelProps>((
7868 } ,
7969 className ,
8070 // ? 修改为details实现后动画是作用在details元素上 需要将motionName设置在details上
81- supportsDetailsContentSelector && openMotion ?. motionName ,
71+ openMotion ?. motionName ,
8272 ) ;
8373
8474 const headerClassName = classNames (
@@ -98,68 +88,6 @@ const CollapsePanel = React.forwardRef<HTMLDetailsElement, CollapsePanelProps>((
9888 } ;
9989
10090 // ======================== 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-
16391 return (
16492 < details { ...resetProps } ref = { ref } className = { collapsePanelClassNames } open = { isActive } >
16593 < summary { ...headerProps } >
@@ -173,7 +101,16 @@ const CollapsePanel = React.forwardRef<HTMLDetailsElement, CollapsePanelProps>((
173101 </ span >
174102 { ifExtraExist && < div className = { `${ prefixCls } -extra` } > { extra } </ div > }
175103 </ 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 >
177114 </ details >
178115 ) ;
179116} ) ;
0 commit comments