Skip to content

Commit 4a96539

Browse files
chriskrolakmmalerba
authored andcommitted
fix(expansion): MatExpansionHeader transition animations (#13088)
* fix: MatExpansionPanel animations fix MatExpansionPanel when included in a sortable MatTable See issue #11990 for more details. Closes #11990 * fix(expansion): MatExpansionPanel animations fix MatExpansionPanel when included in a sortable MatTable See issue #11990 for more details. Fixes #11990 * fix(expansion): MatExpansionPanel animations fix(expansion): MatExpansionPanel animations fix MatExpansionPanel when included in a sortable MatTable See issue #11990 for more details. Fixes #11990 * fix(expansion): MatExpansionPanel animations fix(expansion): MatExpansionPanel animations fix MatExpansionPanel when included in a sortable MatTable See issue #11990 for more details. Fixes #11990 * Update expansion-animations.ts
1 parent 9c075f5 commit 4a96539

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

src/lib/expansion/expansion-animations.ts

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,42 @@ import {
2020
/** Time and timing curve for expansion panel animations. */
2121
export const EXPANSION_PANEL_ANIMATION_TIMING = '225ms cubic-bezier(0.4,0.0,0.2,1)';
2222

23-
/** Animations used by the Material expansion panel. */
23+
/**
24+
* Animations used by the Material expansion panel.
25+
*
26+
* A bug in angular animation's `state` when ViewContainers are moved using ViewContainerRef.move()
27+
* causes the animation state of moved components to become `void` upon exit, and not update again
28+
* upon reentry into the DOM. This can lead a to situation for the expansion panel where the state
29+
* of the panel is `expanded` or `collapsed` but the animation state is `void`.
30+
*
31+
* To correctly handle animating to the next state, we animate between `void` and `collapsed` which
32+
* are defined to have the same styles. Since angular animates from the current styles to the
33+
* destination state's style definition, in situations where we are moving from `void`'s styles to
34+
* `collapsed` this acts a noop since no style values change.
35+
*
36+
* In the case where angular's animation state is out of sync with the expansion panel's state, the
37+
* expansion panel being `expanded` and angular animations being`void`, the animation from the
38+
* `expanded`'s effective styles (though in a `void` animation state) to the collapsed state will
39+
* occur as expected.
40+
*
41+
* Angular Bug: https://github.com/angular/angular/issues/18847
42+
*/
2443
export const matExpansionAnimations: {
2544
readonly indicatorRotate: AnimationTriggerMetadata;
2645
readonly expansionHeaderHeight: AnimationTriggerMetadata;
2746
readonly bodyExpansion: AnimationTriggerMetadata;
2847
} = {
2948
/** Animation that rotates the indicator arrow. */
3049
indicatorRotate: trigger('indicatorRotate', [
31-
state('collapsed', style({transform: 'rotate(0deg)'})),
50+
state('collapsed, void', style({transform: 'rotate(0deg)'})),
3251
state('expanded', style({transform: 'rotate(180deg)'})),
33-
transition('expanded <=> collapsed', animate(EXPANSION_PANEL_ANIMATION_TIMING)),
52+
transition('expanded <=> collapsed, void => collapsed',
53+
animate(EXPANSION_PANEL_ANIMATION_TIMING)),
3454
]),
3555

3656
/** Animation that expands and collapses the panel header height. */
3757
expansionHeaderHeight: trigger('expansionHeight', [
38-
state('collapsed', style({
58+
state('collapsed, void', style({
3959
height: '{{collapsedHeight}}',
4060
}), {
4161
params: {collapsedHeight: '48px'},
@@ -45,16 +65,17 @@ export const matExpansionAnimations: {
4565
}), {
4666
params: {expandedHeight: '64px'}
4767
}),
48-
transition('expanded <=> collapsed', group([
68+
transition('expanded <=> collapsed, void => collapsed', group([
4969
query('@indicatorRotate', animateChild(), {optional: true}),
5070
animate(EXPANSION_PANEL_ANIMATION_TIMING),
5171
])),
5272
]),
5373

5474
/** Animation that expands and collapses the panel content. */
5575
bodyExpansion: trigger('bodyExpansion', [
56-
state('collapsed', style({height: '0px', visibility: 'hidden'})),
76+
state('collapsed, void', style({height: '0px', visibility: 'hidden'})),
5777
state('expanded', style({height: '*', visibility: 'visible'})),
58-
transition('expanded <=> collapsed', animate(EXPANSION_PANEL_ANIMATION_TIMING)),
78+
transition('expanded <=> collapsed, void => collapsed',
79+
animate(EXPANSION_PANEL_ANIMATION_TIMING)),
5980
])
6081
};

0 commit comments

Comments
 (0)