-
Notifications
You must be signed in to change notification settings - Fork 26.5k
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
base: main
Are you sure you want to change the base?
Conversation
1bc76a4
to
addec4e
Compare
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.
addec4e
to
64c2b76
Compare
There was a problem hiding this 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* 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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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"> |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
This adds a guide for enter and leave animations, and updates the prior guides with enter and leave.