The Angular mat-tab-group
has for each mat-tab
an animation effect already included. The given animation effect is quite annoying and therefore I want to use a different one. I have already one for fadein
and fadeout
from somebody else.
export const fadeAnimation = trigger('fadeAnimation', [
// The '* => *' will trigger the animation to change between any two states
transition('* => *', [
// The query function has three params.
// First is the event, so this will apply on entering or when the element is added to the DOM.
// Second is a list of styles or animations to apply.
// Third we add a config object with optional set to true, this is to signal
// angular that the animation may not apply as it may or may not be in the DOM.
query(
':enter',
[style({ opacity: 0 })],
{ optional: true }
),
query(
':leave',
// here we apply a style and use the animate function to apply the style over 0.3 seconds
[style({ opacity: 1 }), animate('0.3s', style({ opacity: 0 }))],
{ optional: true }
),
query(
':enter',
[style({ opacity: 0 }), animate('0.3s', style({ opacity: 1 }))],
{ optional: true }
)
])
]);
Trying to apply it like
<mat-tab-group animationDuration="0ms">
<mat-tab label="First">
<div [@fadeAnimation]="'enter'">
Content 1
</div>
</mat-tab>
<mat-tab label="Second"> Content 2 </mat-tab>
<mat-tab label="Third"> Content 3 </mat-tab>
</mat-tab-group>
fails. Any hints how to apply it properly?
Updated the sample according to the suggestion of @ysf.