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 #11765.
  • Loading branch information
crisbeto authored and jelbourn committed Aug 25, 2018
1 parent 3723191 commit df406cc
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
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
Expand Up @@ -176,8 +176,7 @@ export class MatExpansionPanel extends CdkAccordionItem implements AfterContentI
// 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 df406cc

Please sign in to comment.