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