Skip to content

Commit 53341e5

Browse files
committed
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 3bc52df commit 53341e5

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/lib/expansion/expansion-animations.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,19 @@ export const matExpansionAnimations: {
6565
}), {
6666
params: {expandedHeight: '64px'}
6767
}),
68-
transition('expanded <=> collapsed, void => collapsed', group([
68+
transition('expanded <=> collapsed, expanded <=> void, void => collapsed', group([
6969
query('@indicatorRotate', animateChild(), {optional: true}),
7070
animate(EXPANSION_PANEL_ANIMATION_TIMING),
7171
])),
7272
]),
7373

7474
/** Animation that expands and collapses the panel content. */
7575
bodyExpansion: trigger('bodyExpansion', [
76+
// Note: we also have `void` here as a fallback, because Angular will reset the
77+
// state back to void when the element is being removed. See #11765.
7678
state('collapsed, void', style({height: '0px', visibility: 'hidden'})),
7779
state('expanded', style({height: '*', visibility: 'visible'})),
78-
transition('expanded <=> collapsed, void => collapsed',
79-
animate(EXPANSION_PANEL_ANIMATION_TIMING)),
80+
transition('expanded <=> collapsed, expanded <=> void, void => collapsed',
81+
animate(EXPANSION_PANEL_ANIMATION_TIMING)),
8082
])
8183
};

src/lib/expansion/expansion-panel.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,7 @@ export class MatExpansionPanel extends CdkAccordionItem implements AfterContentI
180180
// with doing it via change detection.
181181
if (phaseName === 'done' && toState === 'expanded') {
182182
classList.add(cssClass);
183-
}
184-
if (phaseName === 'start' && toState === 'collapsed') {
183+
} else if (phaseName === 'start' && (toState === 'collapsed' || toState === 'void')) {
185184
classList.remove(cssClass);
186185
}
187186

0 commit comments

Comments
 (0)