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

[BUG] AnimatePresence won't remove modal if a child animation has a defined exit or similar values #3078

Open
iszard opened this issue Feb 20, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@iszard
Copy link

iszard commented Feb 20, 2025

Setup a Modal within a component that is added to the DOM through a state value.

      <AnimatePresence exitBeforeEnter={true}>
        {isCreatingNewChallenge && <NewChallenge onDone={handleDone} />}
      </AnimatePresence>

The child with a staggered animation looks like.

            <motion.li
              variants={{
                hidden: { opacity: 0, scale: 0.5 },
                visible: { opacity: 1, scale: 1 },
              }}
              // initial={{ opacity: 0, scale: 0.5 }}
              // animate={{ opacity: 1, scale: 1 }}
              exit={{ opacity: 1, scale: 1 }}
              transition={{ type: "spring", stiffness: 260 }}
              key={image.alt}
              onClick={() => handleSelectImage(image)}
              className={selectedImage === image ? "selected" : undefined}
            >
              <img {...image} />
            </motion.li>

When I comment out the exit prop. The modal will close properly but with an added delay due to the child's exit animation. Looking to set the exit value to prevent a lengthy delay while waiting for this child animation to end.

The following sand box will show that you can open the modal by clicking the add challenge button. Then close or click outside the modal. The modal will animate out but will not be removed ie, backdrop will remain.

sandbox: https://codesandbox.io/p/sandbox/r4vftd

@iszard iszard added the bug Something isn't working label Feb 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant