Skip to content

Commit e96991b

Browse files
crisbetojelbourn
authored andcommitted
fix(expansion): panel appearing as open when parent is animating away
Fixes an issue where the expansion panel will appear as if it is open, if the element is part of a component that is animating away. The issue comes from the fact that Angular resets the animation state to `void` which we don't have in the animation definitions. Fixes #11765.
1 parent f1b65b6 commit e96991b

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/lib/expansion/expansion-animations.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export const matExpansionAnimations: {
3535

3636
/** Animation that expands and collapses the panel header height. */
3737
expansionHeaderHeight: trigger('expansionHeight', [
38-
state('collapsed', style({
38+
state('collapsed, void', style({
3939
height: '{{collapsedHeight}}',
4040
}), {
4141
params: {collapsedHeight: '48px'},
@@ -45,16 +45,19 @@ export const matExpansionAnimations: {
4545
}), {
4646
params: {expandedHeight: '64px'}
4747
}),
48-
transition('expanded <=> collapsed', group([
48+
transition('expanded <=> collapsed, expanded <=> void', group([
4949
query('@indicatorRotate', animateChild(), {optional: true}),
5050
animate(EXPANSION_PANEL_ANIMATION_TIMING),
5151
])),
5252
]),
5353

5454
/** Animation that expands and collapses the panel content. */
5555
bodyExpansion: trigger('bodyExpansion', [
56-
state('collapsed', style({height: '0px', visibility: 'hidden'})),
56+
// Note: we also have `void` here as a fallback, because Angular will reset the
57+
// state back to void when the element is being removed. See #11765.
58+
state('collapsed, void', style({height: '0px', visibility: 'hidden'})),
5759
state('expanded', style({height: '*', visibility: 'visible'})),
58-
transition('expanded <=> collapsed', animate(EXPANSION_PANEL_ANIMATION_TIMING)),
60+
transition('expanded <=> collapsed, expanded <=> void',
61+
animate(EXPANSION_PANEL_ANIMATION_TIMING)),
5962
])
6063
};

src/lib/expansion/expansion-panel.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,7 @@ export class MatExpansionPanel extends _CdkAccordionItem
162162
// with doing it via change detection.
163163
if (phaseName === 'done' && toState === 'expanded') {
164164
classList.add(cssClass);
165-
}
166-
if (phaseName === 'start' && toState === 'collapsed') {
165+
} else if (phaseName === 'start' && (toState === 'collapsed' || toState === 'void')) {
167166
classList.remove(cssClass);
168167
}
169168

0 commit comments

Comments
 (0)