Skip to content

Commit

Permalink
fix(expansion): panel appearing as open when parent is animating away
Browse files Browse the repository at this point in the history
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 angular#11765.
  • Loading branch information
crisbeto committed Aug 20, 2018
1 parent b9651df commit 39ddff9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
11 changes: 7 additions & 4 deletions src/lib/expansion/expansion-animations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const matExpansionAnimations: {

/** Animation that expands and collapses the panel header height. */
expansionHeaderHeight: trigger('expansionHeight', [
state('collapsed', style({
state('collapsed, void', style({
height: '{{collapsedHeight}}',
}), {
params: {collapsedHeight: '48px'},
Expand All @@ -45,16 +45,19 @@ export const matExpansionAnimations: {
}), {
params: {expandedHeight: '64px'}
}),
transition('expanded <=> collapsed', group([
transition('expanded <=> collapsed, expanded <=> void', group([
query('@indicatorRotate', animateChild(), {optional: true}),
animate(EXPANSION_PANEL_ANIMATION_TIMING),
])),
]),

/** Animation that expands and collapses the panel content. */
bodyExpansion: trigger('bodyExpansion', [
state('collapsed', style({height: '0px', visibility: 'hidden'})),
// Note: we also have `void` here as a fallback, because Angular will reset the
// state back to void when the element is being removed. See #11765.
state('collapsed, void', style({height: '0px', visibility: 'hidden'})),
state('expanded', style({height: '*', visibility: 'visible'})),
transition('expanded <=> collapsed', animate(EXPANSION_PANEL_ANIMATION_TIMING)),
transition('expanded <=> collapsed, expanded <=> void',
animate(EXPANSION_PANEL_ANIMATION_TIMING)),
])
};
3 changes: 1 addition & 2 deletions src/lib/expansion/expansion-panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,7 @@ export class MatExpansionPanel extends CdkAccordionItem
// with doing it via change detection.
if (phaseName === 'done' && toState === 'expanded') {
classList.add(cssClass);
}
if (phaseName === 'start' && toState === 'collapsed') {
} else if (phaseName === 'start' && (toState === 'collapsed' || toState === 'void')) {
classList.remove(cssClass);
}

Expand Down

0 comments on commit 39ddff9

Please sign in to comment.