|
1 | 1 | import classNames from 'classnames';
|
2 | 2 | import KeyCode from '@rc-component/util/lib/KeyCode';
|
| 3 | +import CSSMotion from '@rc-component/motion'; |
3 | 4 | import React from 'react';
|
4 | 5 | import type { CollapsePanelProps } from './interface';
|
5 | 6 | import PanelContent from './PanelContent';
|
@@ -68,8 +69,6 @@ const CollapsePanel = React.forwardRef<HTMLDetailsElement, CollapsePanelProps>((
|
68 | 69 | [`${prefixCls}-item-disabled`]: disabled,
|
69 | 70 | },
|
70 | 71 | className,
|
71 |
| - // ? 修改为details实现后动画是作用在details元素上 需要将motionName设置在details上 |
72 |
| - openMotion?.motionName, |
73 | 72 | );
|
74 | 73 |
|
75 | 74 | const headerClassName = classNames(
|
@@ -102,16 +101,31 @@ const CollapsePanel = React.forwardRef<HTMLDetailsElement, CollapsePanelProps>((
|
102 | 101 | </span>
|
103 | 102 | {ifExtraExist && <div className={`${prefixCls}-extra`}>{extra}</div>}
|
104 | 103 | </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} |
110 | 108 | forceRender={forceRender}
|
111 |
| - role={accordion ? 'tabpanel' : undefined} |
| 109 | + removeOnLeave={destroyOnHidden} |
112 | 110 | >
|
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> |
115 | 129 | </details>
|
116 | 130 | );
|
117 | 131 | });
|
|
0 commit comments