Skip to content

(animate.enter) and (animate.leave) #63127

Closed

Description

@rupisaini123

Which @angular/* package(s) are the source of the bug?

animations, core

Is this a regression?

No

Description

if using @if directive to show and remove an element and the exit animation is longer as compared to enter animation and we switch back the toggle to true, this add additional element to DOM again with enter animation while other element is already in leave animation

TEMPLATE

@if (isOpen()) {
    <div
      (animate.enter)="enterAnimation($event)"
      (animate.leave)="leaveAnimation($event)">
<p>ELEMENT</p>
</div>
}

enterAnimation(event: any) {
    console.log('enterAnimation', event);
    gsap.fromTo(
      event.target,
      {
        yPercent: 100, // start off-screen above
        opacity: 0
      },
      {
        yPercent: 0, // slide down into place
        opacity: 1,
        duration: .5,
        ease: "power1.out",
        onComplete: () => {
          event.animationComplete();
        }
      }
    );
  }

  leaveAnimation(event: any) {
    console.log('leaveAnimation', event);

    gsap.to(event.target,
      {
        yPercent: 100, // slide down into place
        opacity: 0,
        duration: 10,
        ease: "power1.in",
        onComplete: () => {
          event.animationComplete();
        }
      }
    );
  }

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw


Please provide the environment you discovered this bug in (run ng version)


Anything else?

No response

Activity

  1. shannonvc commented on Aug 13, 2025

    @shannonvc
    Contributor

    This is a duplicate of #63020 and will be fixed by #63048

  2. thePunderWoman commented on Aug 13, 2025

    @thePunderWoman
    Contributor

    This may still be a bug. The event binding version has a different code path than the class version. If you can provide a minimal reproduction with the RC release, that would be appreciated.

  3. added
    area: core
    core: animations
    on Aug 13, 2025
  4. added this to the needsTriage milestone on Aug 13, 2025
  5. rupisaini123 commented on Aug 13, 2025

    @rupisaini123
    Author
  6. imaksp commented on Aug 15, 2025

    @imaksp
    Contributor

    Hi, may be this can be fixed by tracking leave event in new class field and manually calling leaveEvent.animationComplete() in enter code.

  7. imaksp commented on Aug 15, 2025

    @imaksp
    Contributor

    Hi all, I believe current behaviour is good enough, ideally to prevent abrupt animation element should be kept in DOM on leave,
    and if user opens menu while menu close animation is running we could reverse the leave animation using JS. smooth animation won't be possible if element gets removed on leave.

  8. thePunderWoman commented on Aug 18, 2025

    @thePunderWoman
    Contributor

    So the reason I didn't initially apply any fix for this on the event binding version is because the control is in the user space. If you're using a third-party animation library, Angular only knows when to remove the element by when you call the animationComplete() function. So you could track these programmatically in the app code and call them yourself. Though I think that's possibly less ideal. I think we can look at applying a similar fix for the event binding version that we did for the classes and make them consistent.

  9. added 3 commits that reference this issue on Aug 18, 2025
    01914eb
    87ea601
    bdc3167
  10. added a commit that references this issue on Aug 18, 2025
    a7cfb42
  11. angular-automatic-lock-bot commented on Sep 18, 2025

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  12. locked and limited conversation to collaborators on Sep 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: corecore: animations

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions