Skip to content

docs: Update docs and add new animation guide #62874

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

thePunderWoman
Copy link
Contributor

This adds a guide for enter and leave animations, and updates the prior guides with enter and leave.

@thePunderWoman thePunderWoman added action: review The PR is still awaiting reviews from at least one requested reviewer target: minor This PR is targeted for the next minor release area: docs Related to the documentation labels Jul 29, 2025
@ngbot ngbot bot added this to the Backlog milestone Jul 29, 2025
@thePunderWoman thePunderWoman requested a review from JeanMeche July 29, 2025 14:27
Copy link

github-actions bot commented Jul 29, 2025

Deployed adev-preview for 64c2b76 to: https://ng-dev-previews-fw--pr-angular-angular-62874-adev-prev-z5std68n.web.app

Note: As new commits are pushed to this pull request, this link is updated after the preview is rebuilt.

This adds a guide for enter and leave animations, and updates the prior guides with enter and leave.
Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General comments:

  • For all the examples: the docs should no longer suffix files with .component.ts
  • In a follow-up PR, it would be nice to give a little visual polish to the examples over the plain HTML look


* Without animations, web page transitions can seem abrupt and jarring
* Motion greatly enhances the user experience, so animations give users a chance to detect the application's response to their actions
* Good animations intuitively call the user's attention to where it is needed
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Good animations intuitively call the user's attention to where it is needed
* Good animations can smoothly direct the user's attention throughout a workflow


## `animate.enter`

You can use `animate.enter` to animate elements as they __enter__ the DOM. You can define enter animations using CSS classes with either transforms or keyframe animations. Here's an example:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
You can use `animate.enter` to animate elements as they __enter__ the DOM. You can define enter animations using CSS classes with either transforms or keyframe animations. Here's an example:
You can use `animate.enter` to animate elements as they __enter__ the DOM. You can define enter animations using CSS classes with either transforms or keyframe animations:

IMO the presence of the example implies "Here is an example"

(same comment for other examples)


You can use `animate.enter` to animate elements as they __enter__ the DOM. You can define enter animations using CSS classes with either transforms or keyframe animations. Here's an example:

<docs-code-multifile preview path="adev/src/content/examples/animations/src/app/enter-and-leave/enter.component.ts">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For all of the examples, I would make the height of the container larger so there's not a jump in height when you activate the animation

<docs-code header="src/app/enter.component.css" path="adev/src/content/examples/animations/src/app/enter-and-leave/enter.component.css"/>
</docs-code-multifile>

When the animation completes, Angular removes the class or classes that you specified in `animate.enter` from the DOM. This means they will only be present when the animation is active.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
When the animation completes, Angular removes the class or classes that you specified in `animate.enter` from the DOM. This means they will only be present when the animation is active.
When the animation completes, Angular removes the class or classes that you specified in `animate.enter` from the DOM. Animation classes are only be present while the animation is active.

nit: always present tense (avoid "will")


When the animation completes, Angular removes the class or classes that you specified in `animate.enter` from the DOM. This means they will only be present when the animation is active.

NOTE: When using multiple keyframe animations or transition properties on a given element, Angular will wait to remove the classes until the longest of those animations has completed.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
NOTE: When using multiple keyframe animations or transition properties on a given element, Angular will wait to remove the classes until the longest of those animations has completed.
NOTE: When using multiple keyframe animations or transition properties on an element, Angular removes all classes only _after_ the longest animation has completed.

nit: present tense, brevity
(same comment for leave below)


IMPORTANT: You **must** call the `animationComplete()` function when using `animate.leave`, or Angular will not remove the element.

If you fail to call `animationComplete()` when using `animate.leave`, Angular calls the function automatically after a four-second timeout.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
If you fail to call `animationComplete()` when using `animate.leave`, Angular calls the function automatically after a four-second timeout.
If you don't call `animationComplete()` when using `animate.leave`, Angular calls the function automatically after a four-second delay.


## Testing

TestBed provides built-in support for enabling or disabling animations in your test environment. CSS animations require a browser to run, and many of the APIs are not available in a test environment. So, by default, TestBed will disable animations for you in your test environments.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
TestBed provides built-in support for enabling or disabling animations in your test environment. CSS animations require a browser to run, and many of the APIs are not available in a test environment. So, by default, TestBed will disable animations for you in your test environments.
TestBed provides built-in support for enabling or disabling animations in your test environment. CSS animations require a browser to run, and many of the APIs are not available in a test environment. By default, TestBed disables animations in your test environments.


TestBed provides built-in support for enabling or disabling animations in your test environment. CSS animations require a browser to run, and many of the APIs are not available in a test environment. So, by default, TestBed will disable animations for you in your test environments.

If you would like to test that the animations are animating in a browser test, for example an end-to-end test, you can configure TestBed to enable animations by specifying `animationsEnabled: true` in your test configuration.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
If you would like to test that the animations are animating in a browser test, for example an end-to-end test, you can configure TestBed to enable animations by specifying `animationsEnabled: true` in your test configuration.
If you want to test that the animations are animating in a browser test, for example an end-to-end test, you can configure TestBed to enable animations by specifying `animationsEnabled: true` in your test configuration.


This will configure animations in your test environment to behave normally.

NOTE: Some test environments do not announce animation events like `animationstart`, `animationend` and their transition event equivalents.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Announce?

@@ -1,6 +1,6 @@
# Migrating away from Angular's Animations package

Almost all the features supported by `@angular/animations` have simpler alternatives with native CSS. Consider removing the Angular Animations package from your application, as the package can contribute around 60 kilobytes to your JavaScript bundle. Native CSS animations offer superior performance, as they can benefit from hardware acceleration. Animations defined in the animations package lack that ability. This guide walks through the process of refactoring your code from `@angular/animations` to native CSS animations.
The `@angular/animations` package is deprecated as of v20.2, which also introduced the new `animate.enter` and `animate.leave` feature to add animations to your application. Using this new featureset, you can replace all the animations you did with the `@angular/animations` package with pure CSS or even third party animation libraries. Removing `@angular/animations` from your application will cut 60 kilobytes to your JavaScript bundle. Native CSS animations also offer superior performance, as they can benefit from hardware acceleration. Animations defined in the animations package lack that ability. This guide walks through the process of refactoring your code from `@angular/animations` to native CSS animations.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The `@angular/animations` package is deprecated as of v20.2, which also introduced the new `animate.enter` and `animate.leave` feature to add animations to your application. Using this new featureset, you can replace all the animations you did with the `@angular/animations` package with pure CSS or even third party animation libraries. Removing `@angular/animations` from your application will cut 60 kilobytes to your JavaScript bundle. Native CSS animations also offer superior performance, as they can benefit from hardware acceleration. Animations defined in the animations package lack that ability. This guide walks through the process of refactoring your code from `@angular/animations` to native CSS animations.
The `@angular/animations` package is deprecated as of v20.2, which also introduced the new `animate.enter` and `animate.leave` feature to add animations to your application. Using these new features, you can replace all animations based on `@angular/animations` with plain CSS or JS animation libraries. Removing `@angular/animations` from your application can significantly reduce the size of your JavaScript bundle. Native CSS animations generally offer superior performance, as they can benefit from hardware acceleration. This guide walks through the process of refactoring your code from `@angular/animations` to native CSS animations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action: review The PR is still awaiting reviews from at least one requested reviewer adev: preview area: docs Related to the documentation target: minor This PR is targeted for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants