Skip to content

Provide alternative to [@.disabled] for new animate syntax. #63161

Closed

Description

@ahimik

Which @angular/* package(s) are relevant/related to the feature request?

No response

Description

Currently, with the Angular animations package, it is possible to disable all animations within a given DOM subtree by using the special [@.disabled] binding.
A very common use case looks like this:

<div>
  
  @if (show()) {

    <!--Here we can disable all children animations when switching show() signal-->
    <app-child-component [@.disabled]="disableAnimations()">

      <!--Assume this is template of app-child-component:-->
      
        @for (product of products(); track product.id) {
          
          <div @expandOnEnter @collapseOnLeave></div>
           ...
          
        }
    
    </app-child-component>
    
  }
  
</div>

However, there is currently no alternative for disabling animations for a given DOM subtree using new animate syntax. This means I have to pass a variable through the entire component tree and manually apply it to every animated element:

<div class="parent">
  
  @if (show()) {

    <!--Here we can disable all children animations when switching show() signal-->
    <app-child-component>

      <!--Assume this is template of app-child-component:-->
      
        @for (product of products(); track product.id) {
          
          <div [animate.enter]="animationsDisabled() ? null : 'expand'"
               [animate.leave]="animationsDisabled() ? null : 'collapse'">
                  ...
          </div>
          
        }
    
    </app-child-component>
    
  }
  
</div>

Proposed solution

Introduce a mechanism to disable leave, enter, or both animations for a specific DOM subtree:

<!--Example 1: disable all animations for the whole DOM subtree by default-->
<div [animate.disabled]="condition()">
</div>

<!--Example 2: disable only enter or leave animations-->
<div [animate.enter.disabled]="condition()">
</div>

<div [animate.leave.disabled]="condition()">
</div>

Ideally, these attributes should be host-bindable or even changeable programmatically.
There is one limitation I haven’t been able to solve with the current [@.disabled] syntax: it is not possible to disable animations exactly before a component is destroyed, because the OnDestroy hook is invoked too late. So it will be great to address it as well.

Alternatives considered

Manual condition() for every animated element.

Activity

  1. added
    area: core
    core: animations
    on Aug 14, 2025
  2. added this to the needsTriage milestone on Aug 14, 2025
  3. thePunderWoman commented on Aug 18, 2025

    @thePunderWoman
    Contributor

    Can you provide your use case for why you'd need to disable animations like this? TestBed already automatically disables the animation bindings in test. Otherwise since this is pure css and controllable via your code, you can toggle your classes however you like.

    Could you not also toggle a class on the parent div that would change the animation classes behavior such that the animation does not run?

    <!--Here we can disable all children animations when switching show() signal-->
    <div class="parent" [class.disableAnimations]="!show()">
      
      @if (show()) {
        <app-child-component>
    
          <!--Assume this is template of app-child-component:-->
          
            @for (product of products(); track product.id) {
              
              <div animate.enter="expand" animate.leave="collapse">
                      ...
              </div>
              
            }
        
        </app-child-component>
        
      }
      
    </div>
    

    Then you can just update your css to include the animation when .disableAnimations is not in the selector specificity.

  4. added
    needs: clarification
    on Aug 18, 2025
  5. ahimik commented on Aug 18, 2025

    @ahimik
    Author

    Hi @thePunderWoman — I agree this is doable with a helper class like:

    .animations-disabled, .animations-disabled * {
      animation-duration: 0ms !important;
      animation-delay: 0ms !important;
      transition-duration: 0ms !important;
      transition-delay: 0ms !important;
    }

    However, fully removing animations/transitions (e.g. animation: none) isn’t ideal in my case: Angular still expects the enter/leave animation to complete, and when nothing runs it can end up waiting until a timeout. If I’m mistaken about that behavior, I’d really appreciate a pointer to the recommended approach.

    The trickier part is (animate.enter) and (animate.leave) callbacks. On every binding I have to add logic to detect whether animations are disabled (e.g., walk up the DOM to find an .animations-disabled ancestor or check computed styles). That adds boilerplate, that's why I’m hoping for framework-level support.

  6. thePunderWoman commented on Aug 18, 2025

    @thePunderWoman
    Contributor

    You could also make the animate classes computeds that update to null when the show() changes to false. that would mean the animate bindings wouldn't expect anything to run.

  7. thePunderWoman commented on Aug 18, 2025

    @thePunderWoman
    Contributor

    I would also ask that you create a running minimal reproduction so we can see what the difficulty here is and explore more. So please create that in stackblitz for us.

  8. added
    needs reproduction
    on Aug 18, 2025
  9. modified the milestones: needsTriage, Backlog on Aug 18, 2025
  10. removed
    needs reproduction
    needs: clarification
    on Aug 19, 2025
  11. removed this from the Backlog milestone on Aug 19, 2025
  12. 1 remaining item

  13. modified the milestones: Backlog, needsTriage on Aug 19, 2025
  14. thePunderWoman commented on Aug 19, 2025

    @thePunderWoman
    Contributor

    @ahimik OK great. Thank you for providing that. I can see the challenge here. I have a solid idea of what we can do to address this without needing a disabled field and will allow CSS specificity to work properly. :) Stay tuned.

  15. added 2 commits that reference this issue on Aug 19, 2025
    42c0804
    bb33946
  16. added 4 commits that reference this issue on Aug 19, 2025
    2c90cbc
    c11da3c
    8564d8e
    f9d73cc
  17. added a commit that references this issue on Aug 20, 2025
    70afb41
  18. angular-automatic-lock-bot commented on Sep 20, 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.

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

Metadata

Metadata

Labels

area: corecore: animationsstate: has PR

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions