[Complete] RFC - Animation In and Out #62212
Replies: 35 comments 36 replies
-
|
Amazing idea! Q2: no Q3: animate.out |
Beta Was this translation helpful? Give feedback.
-
|
Great Idea. Especially the Callbacks will be very useful in my opinion. |
Beta Was this translation helpful? Give feedback.
-
|
Wow π€©, it would be great to use and implement all these powerful new CSS properties and get the full potential out of them. In my opinion, as I said earlier in the comments, the callback function will be the best feature proposed compared to what already exists (KIS π ). Q1 : Yes Q2 : No, not really useful Q3: No preferences as long as it's explicit Q4: Callback function, 100% for simplicity and readability Q5: To be able to debug / track problems with transitions or performance losses linked to animations in Angular Devtools( or to add direct compatibility with what Chrome already offers) |
Beta Was this translation helpful? Give feedback.
-
|
Q1: No, as it easily would lead to "too much logic in template", while not providing any additional use-cases. |
Beta Was this translation helpful? Give feedback.
-
|
I think these Animations would be very useful. Other frameworks require external libs for handling the animate-out for example. It would be really nice to have such features. Q1: It's a good idea but I also would offer to style the animation in a Stylesheet by a custom CSS selector, since Angular is known to be better scalable in large codebase and separating HTML and CSS / SCSS is always a good idea. Q2: To keep it consistent I would prefer animate.in. As a framework user I would expect to have the opposite of animate.out. Another reason for having an animate.in is to pass some handler function to animate.in. This behavior is not covered by CSS / SCSS and can be a new feature. Q3: It's shorter to write Q4: In this case Q5: Testing an element with the new Vitest Support (or different Unit-, E2E-Frameworks) against before/after styling states can detect breaks in Styles. But instead, I would first focus on a clear animation API since testable animations on the presentational layer are a bit to overcomplicated by now. |
Beta Was this translation helpful? Give feedback.
-
|
Hey! Just a point related to the FAQ / 3): I understand they are not directives... but my ng-brain is a bit confused by the syntax. π
Say, in a way changing the set of trade-offs: <!-- I'd jump directly to the potential selectorless notation (just a draft) -->
<example-cmp animate.out="fancy-animation-class" /> <!-- IMHO this one is really off -->
<example-cmp @animate( out="fancy-animation-class" ) />
<example-cmp [animate.out]="myDynamicCSSClasses" />
<example-cmp @animate( [out]="myDynamicCSSClasses" ) />
<other-example-cmp (animate.out)="animateFn($event)" />
<other-example-cmp @animate( (out)="animateFn($event)" ) />Consequences:
Just an idea: I hope I haven't missed anything obvious! |
Beta Was this translation helpful? Give feedback.
-
|
I heard that the team is moving to native CSS styles from the Material team when proposing animation improvements, and finally here it is! The new solution is quite flexible and ergonomic, and I especially like that the function pattern supports third party animation libraries.
Q1: No. I personally is very against writing plain styles in the template. Q2: I do prefer having Q3: I propose Q4: I prefer Option 2. Why should we introduce a magic method if there is a Web standard for extending events, which is perfect for our use case? In practice, rather than Q5: I would like to manually re-trigger enter and leave animations. I can imagine there are a lot of edge cases to handle but I still would like to re-trigger them if possible. One feature that I really missed in the new API is to block child animations when parent animations are performing, and the ability to manually start or delay child animations. |
Beta Was this translation helpful? Give feedback.
-
|
Nice to see some input/discussion. I already wondered after the previous discussions around animations that we'd be seeing something like this. Good to get some input. I would prefer enter/leave as that tells me more regarding what animation to expect. To me in/out can also relate to the direction or influence of the animation. What I do wonder, for many animations I also need to do classes while it is animating. A common use case is not showing overflow scrollbars while the component is shrinking. Or alignment issues that may arise. Or making sure that the element animates between x and y. And so on. So that we move from something that is hidden, to something is animating, to something that is visible to something that is animating again and to something that is hidden once more. Where do these events/classes take place? Is this the part while animating or is this the hidden/visible parts? Am I right to assume that you would combine this with an @if or something and that the enter/leave are classes that take place while showing/hiding? |
Beta Was this translation helpful? Give feedback.
-
I don't believe that's necessary. Given that both
I don't feel strongly here. I would prefer using
While I do like the terseness of in/out, I wonder if it would be better to align with
Option 2, for a couple of reasons. A animateFn = (event: AnimationEvent) => {
const allDone = Promise.all(event.element.getAnimations().map(a => a.finished));
event.waitUntil(allDone);
}The example provided for this option can be simplified using animateFn = (event: AnimationEvent) => {
const { promise, resolve } = Promise.withResolvers();
animate(event.element, {
x: '16rem',
delay: 500,
loop: 2,
alternate: true,
onComplete: resolve,
});
event.waitUntil(promise);
}
Not sure I would actually test animations personally in unit tests. As long as the everything looks right after enter/leave animations. |
Beta Was this translation helpful? Give feedback.
-
|
1. Should animate.in and animate.out support direct styles (like ngStyle)? But for complex animations, CSS classes (and tailwind) are still better because they keep the code clean. 2. Is 3. What names are better? animate.in/out or animate.enter/leave? 4. Which is better callback function or ExtendableEvent? 5. What should testing tools for animations do? |
Beta Was this translation helpful? Give feedback.
-
|
Just an idea regarding Q3: The |
Beta Was this translation helpful? Give feedback.
-
|
Nice to see something like GSAP into this. it reminders me of something I did back in the day building overlays: <div class="canvas_container">
@animate(in: {
opacity:0
x:-300px // or any other measure that indicate out of the stage, container, or screen...
delay: 3000 // or some sort of function or promise that observe other elements so animations can be chained or handled manually
transform: {...}
}, out:{
opacity:1
x:600px // or any other measure that indicate out of the stage, container, or screen...
delay: 100 // or some sort of function or promise that observe other elements so animations can be chained or handled manually
transform: {...}
}, ... other parameters?: {...}) {
<component />
}
</div>parameters could be anything like events, callbacks, etc... notes on in/out: from the perspective of a canvas, elements go in our out. enter or leave are probably synonyms with the same purpose, however a mouse can "enter" or "leave" an element, in our out acts more on the context that elements on the DOM are in the screen as elements of a scene in a canvas. |
Beta Was this translation helpful? Give feedback.
-
|
Question 1: being able to set a css custom variable in a |
Beta Was this translation helpful? Give feedback.
-
|
Question 2: being able to set a specific (dynamic) css class on enter of an element would be beneficial to further fine grain an intro animation. Like the direction of which an element should animate from. Another example would be an animation via GSAP that would can use a local signal for its calculation when an element is added. |
Beta Was this translation helpful? Give feedback.
-
|
Question 3: is the naming convention changing overall for bindings in Angular? |
Beta Was this translation helpful? Give feedback.
-
|
I really like this proposal. It seems much simpler and more ergonomic compared to the old |
Beta Was this translation helpful? Give feedback.
-
This encourages sloppy code, and is particularly detrimental in large applications with reusable and extendable components, and annoys designers when developers drop inline styles in html.
For consistency, yes. I shouldn't need to take two separate approaches for each side of the same coin.
Enter and Leave are consistent with the Angular Animations
The callback function looks cleaner and is easier to understand for people who generally like to avoid directly using Promises.
Disabling when running test suite (already mentioned), and that the animation (and the correct animation) is being triggered when expected. |
Beta Was this translation helpful? Give feedback.
-
|
Great work on this proposal! I believe this is exactly what I needed for applying animations in Angular. Q1: I believe that for consistency, we should avoid supporting direct style setting options like ngStyle bindings here, as ngStyle and ngClass are moving towards deprecation. Q3: I prefer enter and leave. In and out could be misleading, suggesting easing functions rather than the creation or destruction of a component. Additional Suggestion: [animate.in]="{
classes: myDynamicCSSClasses,
onComplete: () => {
// ... do something after the animation ends
}
}" |
Beta Was this translation helpful? Give feedback.
-
|
hi, 1. Animation naming-styleboth animation name in, out does make sense for naming animation, however enter and leave can every body know that about when element or component inserted or removed from DOM, we can associate or bind a class names or arrays of class names to enter & leave 2. Animation callbackboth enter & leave should be handle animation event like (start, complete, restart if user refresh while prev animation not complete yet) and associate this type with enter and leave 3. Animate Route Navigationcombine this new style of animation with modern navigation style view-transition |
Beta Was this translation helpful? Give feedback.
-
|
In which version this update will be introduced ? |
Beta Was this translation helpful? Give feedback.
-
While I'm generally for giving a bit more freedom, it would add unnecessary typing complexity to directives. Unless you want to make something like
What if I want to use GSAP for in and out - using Having
I see
Possibility to disable animations in e2e testing to speed them up - not sure if you covered this in FAQ#5. In general some possibility to switch animations dynamically would be good if possible (eg. user decided to enable reduced motion) Other than that some benchmarking / performance |
Beta Was this translation helpful? Give feedback.
-
Discussion Question 1: Should these options support setting styles directly like ngStyle bindings? (see example)No, but mostly because I don't like ngStyle either and don't think animations should need it. Discussion Question 2: Is animate.in strictly necessary given the platform supports this behavior already?Strictly necessary ? No. Sensible? Yes, for the reason you mentioned of having a symmetrical API. If you provide animate.out, given the history of the angular animations package, I expect also to find an animate.in, even if technically it's not that necessary. Discussion Question 3: What is your preference on the naming? animate.in and animate.out? animate.enter and animate.leave? Something else?enter and leave, solely for consistent vocabulary with angular animations and because they're solid words for this. Discussion Question 4: Which of these 2 options for using functions is the most ideal to you, and why? Do you have an alternative suggestion?No preference Discussion Question 5: What would you want out of testing tools for animations?At my workplace we mostly want to be able to test "Is this specific animation running?". I think for that purpose it would already suffice if I could check if the CSS class associated with the animation is currently being applied or not. The rest would just be able to use |
Beta Was this translation helpful? Give feedback.
-
|
Did you consider the implication this will have on routing transitions? |
Beta Was this translation helpful? Give feedback.
-
|
I wish Angular supported global animations for |
Beta Was this translation helpful? Give feedback.
-
|
Will it also work seamlessly with the |
Beta Was this translation helpful? Give feedback.
-
|
My comments will be from the perspective of library maintainer. So this is written under assumption that component code isnt directly available to the consumer.
Yes! This would allow to make a simple Input to pass in animation styles. Supporting only class based animation will require to break encapsulation with ng-deep or global styles which is dangerous and risks leaks. Style object can be declared as const and reused safely.
Yes! This is very important for dynamically configured animations. as well for consistency. I would hate to have half of my code use new API for For example: I would trigger parallel animations in some components/directives which would in turn trigger stagger animations inside to create layout with multiple columns where each column staggers its elements in parallel. The animation itself is configured via DI and can be overridden per element. Elements also remember their animation in case they were toggled via We should also add support for animate.in and animate.out in hostbindigs and
in-out is more concise. It is clear its a new API not like enter leave of the old animations.
Option 1: Callback function. If i were a junior developer I would not want to think what it this all extra syntax is for or have some funny async await ideas. I dont see any need to make it a promise because |
Beta Was this translation helpful? Give feedback.
-
|
Q1: Yes |
Beta Was this translation helpful? Give feedback.
-
QuestionsQ1: No, makes it to complicated IMHO Template SyntaxI'd like to provide some feedback and a potential alternative for the proposed template syntax, regarding the use of directive-like bindings ( First, I'm curious if there's a public design doc outlining the decisions, including the pros and cons, behind the current syntax choices. Understanding your thoughts here would be very helpful IMHO. My primary motivation for asking is that I agree with the decision that this new functionality should not be a directive. Based on that, I'd like to propose a different syntax that clearly shows a compile-time transformation rather than mimicking a directive. I suggest we re-use the Here are a few examples of how this could look: HTML Alternatively, to differentiate between static and dynamic values while maintaining the HTML I believe this approach would visually enhance the code and leverage an already established symbol within the framework. |
Beta Was this translation helpful? Give feedback.
-
|
Does the framework actually need an 'animations' feature? First let me start by saying that I have not been privy to the many dicussions that have occured amoungst the team about this feature and while I am certain that they were quite thorough in investigating all possiblities, something keeps nagging me - is this the right solution to the stated problem? It seems to me that the problem that is trying to be solved is that the framework needs to know when it is safe to remove an element from the DOM if there is an 'exit' animation applied to it. Also, it is stated and keeps getting repeated that the Isn't this a life-cycle issue? Shouldn't it perhaps be part of the life-cycle of destroying a component. You mentioned the Just my CDN$0.02 |
Beta Was this translation helpful? Give feedback.
-
|
Instead of Example: <other-example-cmp (onDestroy)="destroyFn($event)" />And extend the event like below: event.cleanUpComplete()Or event.waitUntil(cleanUpPromise) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Authors: @thePunderWoman
Area: Angular Framework
Posted: June 23, 2025
Status: Closed
The Angular team created
@angular/animationsover eight years ago. That was before the native CSS platform had all the native CSS animation features that are built in today, liketransformand@keyframes. At the time,@angular/animationsoffered innovative and important features to bring immersive and beautiful user experiences to your applications. However, so much has changed with the web platform, and the package is now showing its age. This RFC explores our intent to deprecate@angular/animationswith its eventual end-of-life, while also exploring a replacement that modernizes how we do animations in Angular.Over the years, a few problems have emerged with
@angular/animations. The JavaScript size impact of the package is significant, coming in around 60kb. Animations built using@angular/animationsare run in JavaScript and cannot take advantage of hardware acceleration. The@angular/animationsAPI only applies to Angular and does not translate to any skill outside of the Angular ecosystem. Also other widely-used third-party animation libraries have sprung up and become very popular, which are more difficult to use in Angular.We'd like to add two new native features to Angular:
animate.inandanimate.out. Angular works well with pure CSS animations, but there are a few rough edges that we believe these options will solve. We've created a brand new migration guide that outlines how to migrate from@angular/animationsto using pure CSS animations. This guide covers everything needed to migrate, but there are a few rough edges. Animating removal of elements is the most notable. By providing these new options, we can automatically handle the delayed removal for you and let you get back to creating apps your users will love.What kind of feedback are we looking for?
While we're excited to hear any and all comments on the new animation options in Angular, we have additionally called out specific discussion points throughout the RFC for directed feedback. When you leave a comment, be sure to note the open question(s) to which you're responding.
As always, keep our code of conduct in mind. We know that a proposal of this scope significantly impacts Angular and the way you use it in your projects. We appreciate your commitment and investment in this project and ask to keep comments respectful.
Goals
API
Let's talk about the new API and how it will function.
animate.out
Animating elements away from the DOM as they are being removed is a bit tricky to manage manually as there is no
@starting-stylesequivalent natively. Theanimate.outfeature delays removal of an element from the DOM until the associated animation completes.The
animate.outfeature will accept three different types with two different usage patterns. The first pattern is providing astringor string array. This string is the class or classes that contains the animations you'd like to apply as the element is removed. The second pattern is binding to an event with a customfunction. Thefunctionoption is bound to an event that is raised when the element leaves the view. This would allow use of third party animation libraries, like Anime.js or GSAP.Example usages
Discussion Question 1: Should these options support setting styles directly like
ngStylebindings? (see example)animate.in
The need for an
animate.infeature is less important than ananimate.outfeature from a pure CSS perspective, as the CSS platform has added@starting-styles, which allows you to natively specify what animations and styles apply as an element enters the DOM. However, we'll also have a few more options, and for purely symmetrical reasons, we'll want to support the same signature.The
animate.infeature will accept three different value types with 2 different patterns, just like theanimate.outfeature offers. The first pattern is providing astringor string array. This string is the class or classes that contains the animations you'd like to apply as the element enters the view. The second pattern is binding to an event with a customfunction. Thefunctionoption is bound to an event that is raised when the element enters the view. Similarly to `animate.out`, this would allow use of third party animation libraries, like Anime.js or GSAP.If you are just using CSS classes, you do not need to use the
animate.infeature. However,animate.inautomatically removes a specified CSS class after the animation finishes.Example usages
Discussion Question 2: Is
animate.instrictly necessary given the platform supports this behavior already?Discussion Question 3: What is your preference on the naming?
animate.inandanimate.out?animate.enterandanimate.leave? Something else?Animation Function details and options
Both
animate.inandanimate.outalso function as event bindings. This allows you to do whatever you would like to do for animation. The customAnimationEventwill provide access to the element being animated and ananimationCompletefunction. Note thatanimationCompleteis unnecessary foranimate.in, but will be required for the functionality ofanimate.out, as it involves element removal. This section is where we're looking for your feedback.Option 1: Callback function
The native element reference allows you to call
getAnimationsor add more advanced animations with either native platform APIs or with third-party libraries. TheanimationCompletefunction needs to be called when the animation finishes to ensure that any behavior that's supposed to happen when the animation finishes, like element removal, happens. TheanimationCompletecallback has a 4 second timeout, just like native view transitions. So if you forget to call theanimationCompletefunction forout, an error will be thrown at 4 seconds. Here are two examples using third party animation libraries:GSAP
Anime.js
Option 2: ExtendableEvent
Another option is to rely on the
ExtendableEventapi where we can rely on theevent.waitUntil(promise)API. In this case, you would wrap your animation function in a promise that then gets used bywaitUntil. If no promise is provided, the framework will assume no animation and immediately remove the element.Discussion Question 4: Which of these 2 options for using functions is the most ideal to you, and why? Do you have an alternative suggestion?
Discussion Question 5: What would you want out of testing tools for animations?
Future work
Scoped view transitions are currently being considered, which allows for a view transition on an element or DOM subtree. Once these have reached a supported state, we can add support for them, too.
Frequently Asked Questions
Are these directives?
No, they will be built natively into the framework to allow for better optimization and tree-shakability.
Is there anywhere I can try this out?
Yes. You can visit this stackblitz and play with our prototype. Note that the prototype does not support the animation function syntax yet.
Can I get these animal style?
You're thinking of a different in and out.
What happens on the server?
animate.in and animate.out will not execute on the server.
How will tests work with animate.in and animate.out?
We'll be providing a mechanism to disable animations in test environments. Functionally it would be the same as if all animations happened at 0 ms. The on complete functions are still called. So element removal still occurs.
Can I use these as host bindings?
Yes, we will make these host bindable.
Beta Was this translation helpful? Give feedback.
All reactions