Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: appeared again after closing and disappeared very quickly #39

Merged
merged 4 commits into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion src/CSSMotion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export function genCSSMotion(
// Stable children
if (mergedVisible) {
motionChildren = children({ ...mergedProps }, setNodeRef);
} else if (!removeOnLeave && renderedRef.current) {
} else if (!removeOnLeave && renderedRef.current && leavedClassName) {
motionChildren = children(
{ ...mergedProps, className: leavedClassName },
setNodeRef,
Expand Down
39 changes: 39 additions & 0 deletions tests/CSSMotion.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,45 @@ describe('CSSMotion', () => {
},
);

it('leaveClassName should add to dom', () => {
const genMotion = ({ visible }) => {
return (
<CSSMotion
motionName="transition"
visible={visible}
removeOnLeave={false}
leavedClassName={'removed'}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这边设置 leavedClassName 后,下面测试需要移除掉 leavedClassName 才能测出上面的逻辑。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

>
{({ style, className }) => {
return (
<div
style={style}
className={classNames('motion-box', className)}
/>
);
}}
</CSSMotion>
);
};
const { container, rerender } = render(genMotion({visible:false}));

rerender(genMotion({ visible: true }));

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

expect(container.querySelector('.motion-box')).toBeTruthy();
rerender(genMotion({ visible: false }));
act(() => {
jest.runAllTimers();
});

fireEvent.transitionEnd(container.querySelector('.motion-box'));

expect(container.querySelector('.motion-box')).toHaveClass('removed');
});

it('stop transition if config motion to false', () => {
const genMotion = (props?: CSSMotionProps) => (
<CSSMotion motionName="transition" visible {...props}>
Expand Down