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
6 changes: 6 additions & 0 deletions .changeset/spicy-coats-exist.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@nextui-org/modal": patch
"@nextui-org/popover": patch
---

Fixed lazy motion forwardRef issue
Comment thread
wingkwong marked this conversation as resolved.
53 changes: 34 additions & 19 deletions packages/components/modal/src/modal-content.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type {AriaDialogProps} from "@react-aria/dialog";
import type {HTMLMotionProps} from "framer-motion";

import {cloneElement, isValidElement, ReactNode, useMemo} from "react";
import {cloneElement, isValidElement, ReactNode, useMemo, useCallback, ReactElement} from "react";
import {forwardRef} from "@nextui-org/system";
import {DismissButton} from "@react-aria/overlays";
import {TRANSITION_VARIANTS} from "@nextui-org/framer-transitions";
Expand Down Expand Up @@ -90,27 +90,42 @@ const ModalContent = forwardRef<"div", ModalContentProps, KeysToOmit>((props, _)
);
}, [backdrop, disableAnimation, getBackdropProps]);

const RemoveScrollWrapper = useCallback(
({children}: {children: ReactElement}) => {
return (
<RemoveScroll forwardProps enabled={shouldBlockScroll && isOpen} removeScrollBar={false}>
{children}
</RemoveScroll>
);
},
[shouldBlockScroll, isOpen],
);

const contents = disableAnimation ? (
<RemoveScrollWrapper>
<div className={slots.wrapper({class: classNames?.wrapper})}>{content}</div>
</RemoveScrollWrapper>
) : (
<LazyMotion features={domAnimation}>
<RemoveScrollWrapper>
<m.div
animate="enter"
className={slots.wrapper({class: classNames?.wrapper})}
exit="exit"
initial="exit"
variants={scaleInOut}
{...motionProps}
>
{content}
</m.div>
</RemoveScrollWrapper>
</LazyMotion>
);

return (
<div tabIndex={-1}>
{backdropContent}
<RemoveScroll forwardProps enabled={shouldBlockScroll && isOpen} removeScrollBar={false}>
{disableAnimation ? (
<div className={slots.wrapper({class: classNames?.wrapper})}>{content}</div>
) : (
<LazyMotion features={domAnimation}>
<m.div
animate="enter"
className={slots.wrapper({class: classNames?.wrapper})}
exit="exit"
initial="exit"
variants={scaleInOut}
{...motionProps}
>
{content}
</m.div>
</LazyMotion>
)}
</RemoveScroll>
{contents}
</div>
);
});
Expand Down
55 changes: 34 additions & 21 deletions packages/components/popover/src/popover-content.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type {AriaDialogProps} from "@react-aria/dialog";
import type {HTMLMotionProps} from "framer-motion";

import {DOMAttributes, ReactNode, useMemo, useRef} from "react";
import {DOMAttributes, ReactNode, useMemo, useRef, useCallback, ReactElement} from "react";
import {forwardRef} from "@nextui-org/system";
import {DismissButton} from "@react-aria/overlays";
import {TRANSITION_VARIANTS} from "@nextui-org/framer-transitions";
Expand Down Expand Up @@ -81,29 +81,42 @@ const PopoverContent = forwardRef<"div", PopoverContentProps>((props, _) => {
);
}, [backdrop, disableAnimation, getBackdropProps]);

const RemoveScrollWrapper = useCallback(
({children}: {children: ReactElement}) => {
return (
<RemoveScroll forwardProps enabled={shouldBlockScroll && isOpen} removeScrollBar={false}>
{children}
</RemoveScroll>
);
},
[shouldBlockScroll, isOpen],
);

const contents = disableAnimation ? (
<RemoveScrollWrapper>{content}</RemoveScrollWrapper>
) : (
<LazyMotion features={domAnimation}>
<RemoveScrollWrapper>
<m.div
animate="enter"
exit="exit"
initial="initial"
style={{
...getTransformOrigins(placement === "center" ? "top" : placement),
}}
variants={TRANSITION_VARIANTS.scaleSpringOpacity}
{...motionProps}
>
{content}
</m.div>
</RemoveScrollWrapper>
</LazyMotion>
);

return (
<div {...getPopoverProps()}>
{backdropContent}
<RemoveScroll forwardProps enabled={shouldBlockScroll && isOpen} removeScrollBar={false}>
{disableAnimation ? (
content
) : (
<LazyMotion features={domAnimation}>
<m.div
animate="enter"
exit="exit"
initial="initial"
style={{
...getTransformOrigins(placement === "center" ? "top" : placement),
}}
variants={TRANSITION_VARIANTS.scaleSpringOpacity}
{...motionProps}
>
{content}
</m.div>
</LazyMotion>
)}
</RemoveScroll>
{contents}
</div>
);
});
Expand Down