diff --git a/src/DrawerPopup.tsx b/src/DrawerPopup.tsx index 4e53f84f..6f9772a2 100644 --- a/src/DrawerPopup.tsx +++ b/src/DrawerPopup.tsx @@ -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'; @@ -331,7 +331,6 @@ const DrawerPopup: React.ForwardRefRenderFunction< const content = ( { 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) => ( + + ); + + 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', + ); + }); });