Repository navigation
Description
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
thePunderWoman commentedon Aug 18, 2025
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?
Then you can just update your css to include the animation when
.disableAnimationsis not in the selector specificity.ahimik commentedon Aug 18, 2025
Hi @thePunderWoman — I agree this is doable with a helper class like:
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.thePunderWoman commentedon Aug 18, 2025
You could also make the animate classes computeds that update to
nullwhen theshow()changes to false. that would mean the animate bindings wouldn't expect anything to run.thePunderWoman commentedon Aug 18, 2025
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.
ahimik commentedon Aug 19, 2025
@thePunderWoman , here is the example: https://stackblitz.com/edit/stackblitz-starters-tw6io2xc?file=src%2Fchild1.component.ts
1 remaining item
thePunderWoman commentedon Aug 19, 2025
@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.
fix(core): handle cases where classes added have no animations
fix(core): handle cases where classes added have no animations
fix(core): handle cases where classes added have no animations
fix(core): handle cases where classes added have no animations
fix(core): handle cases where classes added have no animations
fix(core): handle cases where classes added have no animations (#63242)
fix(core): handle cases where classes added have no animations (angul…
angular-automatic-lock-bot commentedon Sep 20, 2025
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.