Skip to content

Commit dba7f64

Browse files
committed
feat: 恢复CSSMotion调用
1 parent 4ddcf52 commit dba7f64

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

docs/examples/_util/motionUtil.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type {
66

77
const getCollapsedHeight: MotionEventHandler = () => ({ height: 0, opacity: 0 });
88
const getRealHeight: MotionEventHandler = (node) => ({ height: node.scrollHeight, opacity: 1 });
9-
const getCurrentHeight: MotionEventHandler = (node) => ({ height: node.offsetHeight });
9+
const getCurrentHeight: MotionEventHandler = (node) => ({ height: node?.offsetHeight ?? 0 });
1010
const skipOpacityTransition: MotionEndEventHandler = (_, event) =>
1111
(event as TransitionEvent).propertyName === 'height';
1212

src/Panel.tsx

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import classNames from 'classnames';
22
import KeyCode from '@rc-component/util/lib/KeyCode';
3+
import CSSMotion from '@rc-component/motion';
34
import React from 'react';
45
import type { CollapsePanelProps } from './interface';
56
import PanelContent from './PanelContent';
@@ -68,8 +69,6 @@ const CollapsePanel = React.forwardRef<HTMLDetailsElement, CollapsePanelProps>((
6869
[`${prefixCls}-item-disabled`]: disabled,
6970
},
7071
className,
71-
// ? 修改为details实现后动画是作用在details元素上 需要将motionName设置在details上
72-
openMotion?.motionName,
7372
);
7473

7574
const headerClassName = classNames(
@@ -102,16 +101,31 @@ const CollapsePanel = React.forwardRef<HTMLDetailsElement, CollapsePanelProps>((
102101
</span>
103102
{ifExtraExist && <div className={`${prefixCls}-extra`}>{extra}</div>}
104103
</summary>
105-
<PanelContent
106-
prefixCls={prefixCls}
107-
classNames={customizeClassNames}
108-
styles={styles}
109-
isActive={isActive}
104+
<CSSMotion
105+
visible={isActive}
106+
leavedClassName={`${prefixCls}-panel-hidden`}
107+
{...openMotion}
110108
forceRender={forceRender}
111-
role={accordion ? 'tabpanel' : undefined}
109+
removeOnLeave={destroyOnHidden}
112110
>
113-
{children}
114-
</PanelContent>
111+
{({ className: motionClassName, style: motionStyle }, motionRef) => {
112+
return (
113+
<PanelContent
114+
ref={motionRef}
115+
prefixCls={prefixCls}
116+
className={motionClassName}
117+
classNames={customizeClassNames}
118+
style={motionStyle}
119+
styles={styles}
120+
isActive={isActive}
121+
forceRender={forceRender}
122+
role={accordion ? 'tabpanel' : undefined}
123+
>
124+
{children}
125+
</PanelContent>
126+
);
127+
}}
128+
</CSSMotion>
115129
</details>
116130
);
117131
});

0 commit comments

Comments
 (0)