Skip to content

Commit f5ded4a

Browse files
authored
fix: Move motion to motion props (#283)
* fix: motion move to wrapper * test: test cov
1 parent 0ac7e1c commit f5ded4a

File tree

3 files changed

+75
-31
lines changed

3 files changed

+75
-31
lines changed

docs/examples/assets/motion.less

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
&-enter,
3232
&-appear,
3333
&-leave {
34+
&-start {
35+
transition: none;
36+
}
37+
3438
&-active {
3539
transition: all @duration;
3640
}

src/DrawerPopup.tsx

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -268,45 +268,46 @@ export default function DrawerPopup(props: DrawerPopupProps) {
268268
}
269269

270270
const panelNode: React.ReactNode = (
271-
<div
272-
className={classNames(`${prefixCls}-content-wrapper`)}
273-
style={{
274-
...wrapperStyle,
275-
...contentWrapperStyle,
276-
...zIndexStyle,
271+
<CSSMotion
272+
key="panel"
273+
{...motionProps}
274+
visible={open}
275+
forceRender={forceRender}
276+
onVisibleChanged={nextVisible => {
277+
afterOpenChange?.(nextVisible);
278+
if (!nextVisible) {
279+
scrollLocker?.unLock();
280+
}
277281
}}
282+
removeOnLeave={false}
283+
leavedClassName={`${prefixCls}-content-hidden`}
278284
>
279-
<CSSMotion
280-
key="panel"
281-
{...motionProps}
282-
visible={open}
283-
forceRender={forceRender}
284-
onVisibleChanged={nextVisible => {
285-
afterOpenChange?.(nextVisible);
286-
if (!nextVisible) {
287-
scrollLocker?.unLock();
288-
}
289-
}}
290-
removeOnLeave={false}
291-
leavedClassName={`${prefixCls}-content-hidden`}
292-
>
293-
{({ className: motionClassName, style: motionStyle }, motionRef) => {
294-
return (
285+
{({ className: motionClassName, style: motionStyle }, motionRef) => {
286+
return (
287+
<div
288+
className={classNames(
289+
`${prefixCls}-content-wrapper`,
290+
motionClassName,
291+
)}
292+
style={{
293+
...wrapperStyle,
294+
...motionStyle,
295+
...contentWrapperStyle,
296+
...zIndexStyle,
297+
}}
298+
>
295299
<DrawerPanel
296300
containerRef={motionRef}
297301
prefixCls={prefixCls}
298-
className={classNames(className, motionClassName)}
299-
style={{
300-
...motionStyle,
301-
...style,
302-
}}
302+
className={className}
303+
style={style}
303304
>
304305
{children}
305306
</DrawerPanel>
306-
);
307-
}}
308-
</CSSMotion>
309-
</div>
307+
</div>
308+
);
309+
}}
310+
</CSSMotion>
310311
);
311312

312313
// =========================== Render ===========================

tests/motion.spec.tsx

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { render } from '@testing-library/react';
2+
import React from 'react';
3+
import Drawer from '../src';
4+
5+
jest.mock('rc-motion', () => {
6+
const { genCSSMotion } = jest.requireActual('rc-motion/lib/CSSMotion');
7+
const CSSMotion = genCSSMotion(true);
8+
return CSSMotion;
9+
});
10+
11+
describe('motion', () => {
12+
beforeEach(() => {
13+
jest.useFakeTimers();
14+
});
15+
16+
afterEach(() => {
17+
jest.useRealTimers();
18+
});
19+
20+
// zombieJ: Do not modify patch dom since user use `contentWrapperStyle` for override style
21+
it('motion patch on the correct element', () => {
22+
const { container } = render(
23+
<Drawer
24+
width="93%"
25+
open
26+
getContainer={false}
27+
motion={{ motionName: 'bamboo', motionAppear: true }}
28+
contentWrapperStyle={{ background: 'red' }}
29+
/>,
30+
);
31+
32+
expect(container.querySelector('.rc-drawer-content-wrapper')).toHaveClass(
33+
'bamboo-appear',
34+
);
35+
expect(container.querySelector('.rc-drawer-content-wrapper')).toHaveStyle({
36+
background: 'red',
37+
});
38+
});
39+
});

0 commit comments

Comments
 (0)