Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/DrawerPopup.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { clsx } from 'clsx';
import type { CSSMotionProps } from '@rc-component/motion';
import CSSMotion from '@rc-component/motion';
import { pickAttrs, useEvent } from '@rc-component/util';
import { pickAttrs, useEvent, composeRef } from '@rc-component/util';
import * as React from 'react';
import type { DrawerContextProps } from './context';
import DrawerContext from './context';
Expand Down Expand Up @@ -331,7 +331,6 @@ const DrawerPopup: React.ForwardRefRenderFunction<
const content = (
<DrawerPanel
id={id}
containerRef={motionRef}
prefixCls={prefixCls}
className={clsx(className, drawerClassNames?.section)}
style={{ ...style, ...styles?.section }}
Expand All @@ -343,7 +342,7 @@ const DrawerPopup: React.ForwardRefRenderFunction<
);
return (
<div
ref={wrapperRef}
ref={composeRef(wrapperRef, motionRef)}
className={clsx(
`${prefixCls}-content-wrapper`,
isDragging && `${prefixCls}-content-wrapper-dragging`,
Expand Down
42 changes: 41 additions & 1 deletion tests/motion.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { render, fireEvent } from '@testing-library/react';
import { render, fireEvent, act } from '@testing-library/react';
import React from 'react';
import Drawer from '../src';

Expand Down Expand Up @@ -75,4 +75,44 @@ describe('motion', () => {

expect(closeCount).toBe(1);
});

it('ends the leave motion on the transition end of the content wrapper', () => {
const afterOpenChange = jest.fn();
const motion = { motionName: 'bamboo' };

const renderDrawer = (open: boolean, destroyOnHidden?: boolean) => (
<Drawer
open={open}
destroyOnHidden={destroyOnHidden}
getContainer={false}
motion={motion}
afterOpenChange={afterOpenChange}
/>
);

const { container, rerender } = render(renderDrawer(true));
rerender(renderDrawer(false));

// Wait for the active step, the only phase which binds the motion events
act(() => {
jest.runAllTimers();
});

const wrapper = container.querySelector('.rc-drawer-content-wrapper');
expect(wrapper).toHaveClass('bamboo-leave-active');

// No `motionDeadline` here: only the transition end of the wrapper can settle it
fireEvent.transitionEnd(wrapper);

expect(afterOpenChange).toHaveBeenCalledTimes(1);
expect(afterOpenChange).toHaveBeenCalledWith(false);

act(() => {
jest.runAllTimers();
});

expect(container.querySelector('.rc-drawer-content-wrapper')).toHaveClass(
'rc-drawer-content-wrapper-hidden',
);
});
});
Loading