framer motion exit animations not working. #1058
Answered
by
heyitsarpit
heyitsarpit
asked this question in
Help
-
What's incorrect with my code here? I pass export function HamburgerSideBar() {
const [open, setOpen] = useState(false)
return (
<Dialog.Root onOpenChange={(o) => setOpen(o)}>
<Dialog.Trigger className='relative z-50'>
<HamburgerButton open={open} />
</Dialog.Trigger>
<Dialog.Portal>
<Dialog.Overlay className='fixed inset-0 pointer-events-none bg-black/70 backdrop-blur-sm' />
<AnimatePresence>
{open ? (
<Dialog.Content asChild forceMount>
<motion.div
initial={{ x: '-100%' }}
animate={{ x: 0 }}
exit={{ x: '-100%' }}
transition={{ duration: 0.4, ease: 'linear' }}
className='fixed top-0 left-0 z-50 h-full bg-grey-11 w-96'>
<SidebarContent />
</motion.div>
</Dialog.Content>
) : null}
</AnimatePresence>
</Dialog.Portal>
</Dialog.Root>
)
} |
Beta Was this translation helpful? Give feedback.
Answered by
heyitsarpit
Jan 3, 2022
Replies: 1 comment 2 replies
-
I found the solution - export function HamburgerSideBar() {
const [open, setOpen] = useState(false)
return (
<Dialog.Root onOpenChange={(o) => setOpen(o)}>
<Dialog.Trigger className='relative z-[51]'>
<HamburgerButton open={open} />
</Dialog.Trigger>
<AnimatePresence>
{open ? (
<Dialog.Portal forceMount>
<Dialog.Overlay asChild forceMount>
<motion.div
className='fixed inset-0 z-50 cursor-pointer bg-black/50 backdrop-blur-[10px]'
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
transition={{ duration: 0.4, ease: 'easeInOut' }}></motion.div>
</Dialog.Overlay>
<Dialog.Content asChild forceMount>
<motion.div
initial={{ x: '-100%' }}
animate={{ x: 0 }}
exit={{ x: '-100%' }}
transition={{ duration: 0.4, ease: 'easeInOut' }}
className='fixed top-0 left-0 z-50 h-full w-72 bg-grey-11 md:w-[70vw]'>
<SidebarContent />
</motion.div>
</Dialog.Content>
</Dialog.Portal>
) : null}
</AnimatePresence>
</Dialog.Root>
)
} |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
heyitsarpit
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I found the solution -
You need to put
forceMount
prop on thePortal
and wrap it inAnimatePresence
. Content and overlay will also requireforceMount
.