Merged in fix/modal-fast-close (pull request #2100)

fix - use animateprecence to avoid page freeze

* fix - use animateprecence to avoid page freeze


Approved-by: Michael Zetterberg
This commit is contained in:
Linus Flood
2025-05-15 05:13:17 +00:00
parent d0a3d0c228
commit 1c70047ae8

View File

@@ -1,7 +1,7 @@
"use client"
import { cx } from "class-variance-authority"
import { motion } from "framer-motion"
import { AnimatePresence, motion } from "framer-motion"
import { type PropsWithChildren, useEffect, useState } from "react"
import {
Dialog,
@@ -154,22 +154,28 @@ export default function Modal({
}
}, [isOpen])
const shouldRender = isOpen || animation !== AnimationStateEnum.unmounted
if (!trigger) {
return (
<InnerModal
onAnimationComplete={onAnimationComplete}
animation={animation}
setAnimation={setAnimation}
onToggle={onToggle}
isOpen={isOpen}
title={title}
subtitle={subtitle}
withActions={withActions}
hideHeader={hideHeader}
className={className}
>
{children}
</InnerModal>
<AnimatePresence>
{shouldRender && (
<InnerModal
onAnimationComplete={onAnimationComplete}
animation={animation}
setAnimation={setAnimation}
onToggle={onToggle}
isOpen={isOpen}
title={title}
subtitle={subtitle}
withActions={withActions}
hideHeader={hideHeader}
className={className}
>
{children}
</InnerModal>
)}
</AnimatePresence>
)
}
@@ -182,17 +188,21 @@ export default function Modal({
}
>
{trigger}
<InnerModal
onAnimationComplete={onAnimationComplete}
animation={animation}
setAnimation={setAnimation}
title={title}
subtitle={subtitle}
withActions={withActions}
className={className}
>
{children}
</InnerModal>
<AnimatePresence>
{shouldRender && (
<InnerModal
onAnimationComplete={onAnimationComplete}
animation={animation}
setAnimation={setAnimation}
title={title}
subtitle={subtitle}
withActions={withActions}
className={className}
>
{children}
</InnerModal>
)}
</AnimatePresence>
</DialogTrigger>
)
}