Skip to content

Commit a019463

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 84634cc commit a019463

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ export class MatExpansionPanel extends CdkAccordionItem
155155
// with doing it via change detection.
156156
if (phaseName === 'done' && toState === 'expanded') {
157157
classList.add(cssClass);
158-
} else if (phaseName === 'start' && toState === 'collapsed') {
158+
} else if (phaseName === 'start' && (toState === 'collapsed' || toState === 'void')) {
159159
classList.remove(cssClass);
160160
}
161161
}

0 commit comments

Comments
 (0)